首先封装两个因为兼容问题不好搞的函数
//查看滚动条的滚动距离
function getScrollOffset(){ if(window.pageYOffset){ return{ x : window.pageXOffset, y : window.pageYOffset } }else{ return{ x : document.body.scrollLeft + document.documentElement.scrollLeft, y : document.body.scrollTop + document.documentElement.scrollTop } }}
//查看视口尺寸
function getViewportOffset(){ if(window.innerWidth){ return{ w:window.innerWidth, h:window.innerHeight } }else{ if(document.compatMode == "BackCompat"){ return{ w: document.body.clientWidth, h: document.body.clientHeight } }else{ return{ w:document.documentElement.clientWidth, h:document.documentElement.clientHeight } } }}
然后是scrollBy函数
还是一个应用,比如说自动阅读功能
var start = doc....
var stop = doc...
var timer = 0;
star.onclick = function(){
timer = setInterval(function(){
window.scrollBy(0,10);
),100);
}
stop.onclick = function(){
clearInterval(timer);
}