ad2003
ad2003

Reputation: 323

stop js script when scroll or click

I am using this script to make an autoscroll on my website. When the user opens the website, theres a logo and after an amount of time, the browser scrolls down.

  $(document).ready(function () {
    setTimeout(function(){
       $('#logoclick').trigger('click');
    }, 3100); });

the problem is, that everytime the user enters the website, this script runs, which is bad, because, if the user enters the page on an anchorpoint (e.g: mypage.com#contact) the first thing happens is, that the browser goes to top of the page and then scrolls down.

The question is, how could I just disable the script, e.g. when the user scrolls or clicks?

Thank you!

AD

Upvotes: 0

Views: 316

Answers (1)

Mark Tielemans
Mark Tielemans

Reputation: 1568

You could put this code within an if statement which checks if an anchor is present. If so, don't execute the code.

See here for how to do that.

EDIT

If you also want to stop the animation when the user scrolls, even when no anchor is present, you can do so using a jQuery stop() function in javascripts onScroll event.

See this for the on scroll event. See this for the rather self-explanatory stop method.

Upvotes: 1

Related Questions