晴明的博客园 GitHub      CodePen      CodeWars     

[js] 监听滚动条距离页面顶部的距离

            console.log(document.body.scrollHeight);
            var a = document.body.scrollHeight;
            window.addEventListener("scroll", function(event) {
                var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
                console.log(scrollTop);
                if(scrollTop > (a/2)){
                    console.log('xxxxxxxxxxxxxxxxxxx');
                    
                }
            });

posted @ 2016-02-18 11:05  晴明桑  阅读(6112)  评论(0编辑  收藏  举报