Hi, I'm using mootools to create a delay set time out on a function everytime someone clicks a button. My question is how can I stop executing the function and reset a time out delay to start over. Imagine this: Click and start the time out 10 seconds to do something. But I if click again after 5 seconds I want to restart the counting to the next 10 seconds. The problem is that I can not reset the time out so I get the function executed 5 seconds after second click, 10 seconds after the first click, and 10 seconds again after the second click. And what I want is the function to be executed after the last click... Got it? Here are some experimental javascript mootools code that I was using to try to workarround this: var isClicked = 0; var doIsClicked = function() { isClicked++; (function(){ isClicked = 0; //alert("-1-"+isClicked) }).delay(15000); //alert(isClicked); } var doStandByShowDelay = function() { doIsClicked(); (function(){ //alert("-2 -"+isClicked) if ( isClicked == '0' ){ doStandByShow(); } else{ doStandByShowDelay(); } }).delay(10000); } Code (markup): So, is there anyway to CANCEL a time out Delay so I can start over from zero again???? Thanks!!
I'm not familiar with mootools syntax, so I apologize if this is not quite applicable. However, when dealing with this problem in plain javascript I found that you have to initialize a global variable, then set it to the timeout. To clear it you first have to use clearTimeout(var), then set the var to the new timeout. For example: var timeout = ''; function startTimer() { clearTimeout(timeout); timeout = setTimeout('dostuff()',3000); } Code (markup):
I would agree with skier88 Having a global variable for timeout and updating it everytime some click event occurs would be a great idea... I suppose you can pass the variable as a parameter to the delay statement like delay(timeoutvariable); All the best!
When I set myStandByTimeout = setTimeout(doStandByShow(),30000); Code (markup): Under mootools is executed without the delay. I can only have a delay when I use myStandByTimeout = (function(){ doStandByShow(); }).delay(3000); Code (markup): The thing is.. Hoe can I use clearSetTimeout this way!?
I gos this from Mootolls Docs: var myTimer = myFunction.delay(5000); //Waits 5 seconds then executes myFunction. myTimer = $clear(myTimer); //Cancels myFunction. I will test. Thanks,.
Hi, I'm a newby in javascript. I have found some javascript to move a dif i have some HTML : <p><a onmouseover="javascript:test()" onmouseout="javascript:out()" >Test div move 1</a> </p> <p><a onmouseover="javascript:test1()" onmouseout="javascript:out()" >Test div move 2</a> </p> <p><a onmouseover="javascript:test2()" onmouseout="javascript:out()" >Test div move 3</a> </p> <p><a onmouseover="javascript:test3()" onmouseout="javascript:out()" >Test div move 4</a> </p> Code (markup): and some javascript functions : function test(){ $("box").move({delay:600,to:{left:-1200,top:0}});} function test1(){ $("box").move({delay:600,to:{left:-800,top:0}});} function test2(){ $("box").move({delay:600,to:{left:-400,top:0}});} function test3(){ $("box").move({delay:600,to:{left:-0,top:0}});} function out1(){ $("box").move({delay:100,to:{left:-1600,top:0}});} function out() { clearTimeout('mydelay'); mydelay = setTimeout('out1()',2000);} Code (markup): the timeout has to be reset whene i hover over an other link, but the clearTimeout does nothing. can anyone please help me what's wrong. If nessesary i can place the complete code.