以下是一个示例:http://jsfiddle.net/jquerybyexample/pusqN/light/ 我想在15000px之后停止滚动动画
$(document).ready(function () {
var myInterval = false;
myInterval = setInterval(function () {
var iScroll = $(window).scrollTop();
if (iScroll + $(window).height() == $(document).height()) {
clearInterval(myInterval);
} else {
iScroll = iScroll + 200;
$('html, body').animate({
scrollTop: iScroll
}, 1000);
}
}, 2000);
});
答案 0 :(得分:0)
只需在iScroll + $(window).height() > 15000
中添加条件if
:
...
if (iScroll + $(window).height() == $(document).height() ||
iScroll + $(window).height() > 15000 // Stop after 15000px
) {
clearInterval(myInterval);
}
...