| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- export class scroll_up {
- #button;
- constructor(button) {
- this.#button = button;
- this.#update();
-
- document.addEventListener("scroll", () => {
- this.#update()
- });
- this.#button.addEventListener("click", () => {
- this.scroll();
- });
- }
- scroll() {
- this.#position = 0;
- }
- get #position() {
- return document.scrollingElement.scrollTop;
- }
- set #position(target) {
- document.scrollingElement.scrollTop = target;
- }
- get #visible() {
- return Number(this.#button.style.opacity) === 1;
- }
- set #visible(target) {
- this.#button.style.opacity = (target) ? "1" : "0";
- }
- get #margin() {
- return 20;
- }
- #update() {
- this.#visible = (this.#position > this.#margin);
- }
- }
|