I have an scroll to element snippet as:
$('html,body').animate({
scrollTop: $(window.location.hash).offset().top
},1000);
which is working perfectly but I need to run it after few seconds on getting into the page (with delay), so I used setTimeout()
to get this but now the page jumps to the section (hash) without scrolling or prompting any error message.
setTimeout(function(){
$('html,body').animate({
scrollTop: $(window.location.hash).offset().top
},1000);
}, 2000);
can you please let me know what I am doing wrong and why this is not working with delay?!