javascript - How do I stop and start a function? -


i'm looking pointed in right direction here. i'm beginner javascript there's sort of fundamental thing i'm not understanding. google searches didn't seem since apparently question never asked.

i have game there 60 second countdown once go button pressed. when 60 second countdown running want run function orientationstuff() sorts of stuff on orientationchange. no problem...however

i want orientationstuff() run during 60 second countdown. once hits 0, there no more orientationstuff() going on. once click go again want countdown start again (and consequently orientationstuff()

the simple answer use settimeout function want execute , 60000 milliseconds

settimeout(function(){    // whatever want happen here },60000) 

in terms of starting jquery, if had button class go use

$(document).on('click','.go',function(){     settimeout(function(){        // game on man! game over!!     },60000) }); 

i guess want stop timer - if player wins game. in case capture "id" timer , can use cleartimeout stop it

var gametimerid = null; $(document).on('click','.go',function(){     gametimerid  = settimeout(function(){        // hury, before calls cleartimeout     },60000) });  /// player wins cleartimeout(gametimerid); 

settimeout runs function once. if want execute function repeatedly there similar function setinterval can use too.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -