js 判断滚动条是否停止滚动


<!DOCTYPE html>  
<html>  
<head>  
<meta charset="utf-8">  
<title>js判断滚动条停止</title>  
<style type="text/css">
    .box {
        height: 3000px;
    }
</style>
<script type="text/javascript">  
    var topValue = 0, // 上次滚动条到顶部的距离
        interval = null; // 定时器
    document.onscroll = function() {
        if(interval == null) {
            // 未发起时,启动定时器,1秒1执行
            interval = setInterval(function() {
                if(document.documentElement.scrollTop == topValue) {
                    alert("scroll bar is stopping!");
                    clearInterval(interval);
                    interval = null;
                }
            }, 1000);
        }
        topValue = document.documentElement.scrollTop;
    }  
</script>  
</head>  
    <div class="box"></div>
<body>  
</body>  
</html> 

这个需求是我在写一个固钉的时候遇到的问题,当滚动条滚动时固钉隐藏,当停止滚动时固钉出现


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM