日期:2014-05-16 浏览次数:20410 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<div style="height:1000px"></div>
<script>
var timer, scrollHeight, viewHeight, step = 20, sTop = 0,isScrict=document.compatMode=='CSS1Compat';
document.onclick = function () { clearInterval(timer); }
function Move() {
//设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
if (nowScrollTop < sTop
------解决方案--------------------
(nowScrollTop - top > step)) clearInterval(timer);
sTop += step;
document.documentElement.scrollTop = document.body.scrollTop = sTop;
if (sTop + viewHeight > scrollHeight) {//滚动到底部
clearInterval(timer);
document.documentElement.scrollTop = document.body.scrollTop = 0//跳转到顶部
}
}
window.onresize = function () {
viewHeight = document[isScrict?'documentElement':'body'].clientHeight;