Front page javascript redirect to a set distance

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 :smiley: ) 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.

Hi Rene,

Thanks for reaching out.

Regretfully, providing or enhancing custom code is outside the scope of our theme support. You may seek help from third-party developers or you can avail One , where we answer all the customization on your website.

Hope that helps and thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.