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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> New Document </title>
<script type="text/javascript">
<!--
// 让浏览器出现滚动条
for(var i = 0; i < 100; i++) {
document.write("<br/>");
} var topValue = 0,// 上次滚动条到顶部的距离
interval = null;// 定时器
document.onscroll = function() {
if(interval == null)// 未发起时,启动定时器,1秒1执行
interval = setInterval("test()", 1000);
topValue = document.documentElement.scrollTop || document.body.scrollTop;;
} function test() {
// 判断此刻到顶部的距离是否和1秒前的距离相等
var t1 = document.documentElement.scrollTop || document.body.scrollTop;
if( t1 == topValue) {
alert("scroll is stopping!");
clearInterval(interval);
interval = null;
}
}
//-->
</script>
</head>
<body>
</body>
</html>

 

上一篇:一个JS判断客户端是否已安装某个字体(Only IE)


下一篇:致第一次安装RIME的你