Jon
Jon

Reputation: 6541

end javascript function after 10 seconds

I found a javascript snow script. Here is the fiddle: http://jsfiddle.net/wj2K4/

(very nice)

Its only a gimmick and I don't want it dominating the page, so I want to turn it off after 10 or 30 seconds.

I reckon killing the script would be the easiest way, but I can't find a suitable command. (or similar question on stack)

setTimeout() & setInterval() is not what I am looking for.

Ideas?

This code is pointless but I cant post the question without it:

function doStart() {
if (!s.excludeMobile || !isMobile) {
  if (s.freezeOnBlur) {
    s.events.add(isIE?document:window,'mousemove',doDelayedStart);
  } else {
    doDelayedStart();
  }
}
// event cleanup
s.events.remove(window, 'load', doStart);
  }

Upvotes: 0

Views: 6448

Answers (1)

Muthu Kumaran
Muthu Kumaran

Reputation: 17910

Use s.stop(); to stop snow animations. See the code below, I used setTimeout to stop the animation

function doStart() {
  if (!s.excludeMobile || !isMobile) {
    if (s.freezeOnBlur) {
      s.events.add(isIE?document:window,'mousemove',doDelayedStart);
    } else {
      doDelayedStart();
    }
  }
  // event cleanup
  s.events.remove(window, 'load', doStart);
  setTimeout(function(){s.stop();},15000); //stop after 15 seconds
}

Demo: http://jsfiddle.net/muthkum/wj2K4/1/

Upvotes: 3

Related Questions