+import {Component} from "./component";
-class BackToTop {
+export class BackToTop extends Component {
- constructor(elem) {
- this.elem = elem;
+ setup() {
+ this.button = this.$el;
this.targetElem = document.getElementById('header');
this.showing = false;
this.breakPoint = 1200;
if (document.body.classList.contains('flexbox')) {
- this.elem.style.display = 'none';
+ this.button.style.display = 'none';
return;
}
- this.elem.addEventListener('click', this.scrollToTop.bind(this));
+ this.button.addEventListener('click', this.scrollToTop.bind(this));
window.addEventListener('scroll', this.onPageScroll.bind(this));
}
onPageScroll() {
let scrollTopPos = document.documentElement.scrollTop || document.body.scrollTop || 0;
if (!this.showing && scrollTopPos > this.breakPoint) {
- this.elem.style.display = 'block';
+ this.button.style.display = 'block';
this.showing = true;
setTimeout(() => {
- this.elem.style.opacity = 0.4;
+ this.button.style.opacity = 0.4;
}, 1);
} else if (this.showing && scrollTopPos < this.breakPoint) {
- this.elem.style.opacity = 0;
+ this.button.style.opacity = 0;
this.showing = false;
setTimeout(() => {
- this.elem.style.display = 'none';
+ this.button.style.display = 'none';
}, 500);
}
}
requestAnimationFrame(setPos.bind(this));
}
-}
-
-export default BackToTop;
\ No newline at end of file
+}
\ No newline at end of file