Reputation: 129
I'm trying to make a page scroll down 100px with setTimeout ( 9 sc )
Scroll to bottom with setTimeout
window.onload = toBottom;
function toBottom() {
window.scrollTo(0, document.body.scrollHeight);
}
window.onload = setTimeout(toBottom, 9000);
Scroll down page with pixel
$('html, body').animate({
scrollTop: $(window).scrollTop() + 100
});
Upvotes: 0
Views: 2936
Reputation: 2181
If you want to scroll down to the bottom then instead of using setTimeout use setInterval like below :
setInterval(function(){$('html, body').animate({
scrollTop: $(window).scrollTop() + 100
});},9000);
In case you want to stop auto scrolling, once bottom is reached then use below :
var interval = setInterval(function(){$('html, body').animate({
scrollTop: $(window).scrollTop() + 100
});},9000);
$(window).scroll(function(){
var height = $(window).scrollTop();
var htWindow = $("html body").prop('scrollHeight')-$(window).height() ;
if(height >= htWindow) {
clearInterval(interval);
}
});
Upvotes: 0
Reputation: 14313
I don't see a huge problem with your code other than not putting it inside a setTimeout.
setTimeout(function () {
$('html, body').animate({
scrollTop: $(window).scrollTop() + 100
});
},9000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="height:1100px;width:1px"></div>
Upvotes: 1