Vue监听滚动条事件 点击回到顶部
生活随笔
收集整理的這篇文章主要介紹了
Vue监听滚动条事件 点击回到顶部
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Vue監聽滾動條事件 點擊回到頂部
監聽滾頂條事件:
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);總結
以上是生活随笔為你收集整理的Vue监听滚动条事件 点击回到顶部的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 马斯克“强夺”@x 推特账号
- 下一篇: 三星移动负责人:公司在中国市场朝着“正确