Welcome to WebmasterWorld Guest from 54.167.153.63

Forum Moderators: open

Message Too Old, No Replies

simple Timeout & clear

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

5+ Year Member



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)

5+ Year Member



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

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

Featured Threads

Hot Threads This Week

Hot Threads This Month