监听滚顶条事件:
created () {
this.listenerFunction();
},
beforeDestroy () {
document.removeEventListener("scroll", this.listenerFunction);
},
method () {
listenerFunction(e) {
document.addEventListener('scroll', this.handleScroll, true);
}),
handleScroll () {
console.log(window.pageYOffset)
}
}
点击回顶部:
backTop() { //点击回顶部
// document.body.scrollTop = 0;
// document.documentElement.scrollTop = 0;
$('html').stop().animate({
scrollTop: 0
}, 1000)
},
```
无动画:
window.scrollTo(x-coord, y-coord);