所以这应该是非常简单的我猜,但我是新手,因为代码只运行两次,或者滚动两次而不是我需要的任何数字然后结束,我得到了一些错误。
scrNum
是每次脚本在某个页面上运行时不同的数字,我在页面加载时得到它,它通常是一个小数字。
还有一种更简单的方法可以使用jQuery吗?
var i = 0;
function scroll(){
setTimeout(function(){
//scroll to the bottom of page
window.scrollTo(0, document.body.scrollHeight);
//if less than needed execute again
if( i < scrNum ){
i++;
scroll();
} else
window.scrollTo(0, document.head.scrollHeight);
}, 2000);
}