Welcome to WebmasterWorld Guest from 54.196.231.129

Forum Moderators: open

Message Too Old, No Replies

simple Timeout & clear

     
9:09 pm on Jan 2, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 10, 2005
posts:387
votes: 0


I'm having trouble with what should be a simple Timeout and clear. Here's my code:

function test() {
var Timer = setTimeout(function() {
alert("hello");
}, 1000);
}

test();

The code runs in a slideshow, and when the slide transitions out, I clear the timeout using:

clearTimeout(Timer);

For some reason, the clear causes the slideshow navigation to hang and remain stuck on the current slide. Is there something wrong with my code? Better yet, can I do this w/o coding the Timeout as a function w/in a function? That would likely solve it.
9:25 pm on Jan 2, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 10, 2005
posts:387
votes: 0


I got it. Timer needs to be defined outside the function:

var Timer;
function test() {
Timer = setTimeout(function() {
alert("hello");
}, 1000);
}