Hello everybody.
I have been using the following javascript code in the js section of the front page with success:
var delay=1000 * 5; // sets delay action to 5000 ms = 5 seconds
setTimeout(function(){ window.scrollTo({ top: 288, behavior: 'smooth' }); }, delay);
Now, the problem is that after scrolling down the function still executes (which it should) but it brings in the view all the way to the top of the page, which I would like to avoid.
I am trying to make it execute only when the page is at the top and the user has not scrolled down.
$(window).scroll(function(){
var ws = $(window).scrollTop();
if(ws<=10) // check if at the top of the page within a small range
{
var delay=1000 * 5; // sets delay action to 5000 ms = 5 seconds
setTimeout(function(){ window.scrollTo({ top: 288, behavior: 'smooth' }); }, delay);
}
});
I am not very fluent in javascript (as I am sure you can tell
) but I have been researching a lot and this is the closest I have gotten to a solution but without much success.
Thank you for your time.