【JavaScript】解决document.documentElement.scrollTop为0

最近写项目的时候,发现做一个吸顶效果只有chrome可以获取到滚动的值,其他浏览器都是0

结局方案

做一个兼容性操作即可

 let top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;
 if(top > this.$refs.filmSwiper.$el.offsetHeight)
            {
    
    
                this.isFixed = true;
                // console.log('fixed')
            }
            else{
    
    
                this.isFixed = false;
                // console.log('unfixed')
            }
 }

猜你喜欢

转载自blog.csdn.net/ICe_sea753/article/details/99834148