每个div有500px的高度我想要做的是让屏幕自动滚动每三秒直到到达下一个div位置,一旦它到达最后一个div返回并从头开始并且这样做无限在这里是我的j查询代码
$(document).ready(function(){
myfunction();
});
num = 0;
function myfunction(){
if(num == 1500)
{
num = 0;
}
setTimeout(function(){$('html, body').animate({scrollTop:num}, "normal")},3000);
num = num + 500;
myfunction();
}
答案 0 :(得分:0)
setTimeout(function(){
$('html, body').animate({scrollTop:num}, "normal");
num = num + 500;
myfunction();
}
,3000);
答案 1 :(得分:0)
试试这个
$(document).ready(function () {
var scrollAmount = 0;
var divHeight = $("div").outerHeight();
var pageHeight = $(document).outerHeight();
var interval = setInterval(function () {
if (pageHeight > scrollAmount) {
scrollAmount += divHeight;
}
else {
scrollAmount = 0;
}
$("html, body").animate({
scrollTop: scrollAmount
});
}, 2000);
});