一、vue项目中(获取到父元素)

mounted() {
      document.getElementsByClassName('home')[0].addEventListener('scroll', this.handleScroll, true)
 },
beforeDestroy() {
      document.getElementsByClassName('home')[0].removeEventListener('scroll', this.handleScroll, true)
 },
handleScroll(e) {
        let scrollHeight  = document.getElementsByClassName('home')[0].scrollTop;
        console.log('scrollHeight', scrollHeight);
      }

二、原生JS

window.addEventListener('scroll', () => {console.log(window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop)}, true)

您已经阅读00:00:00欢迎留言评论,喜欢的话就为作者点个赞或者赏颗糖吧! 分享