javascript - SetTimeout Overlapping? -


this piece of code. image goes visible after 23 milliseconds properly, never turns hidden second line tells to. if change 17 milliseconds value greater 23 milliseconds, works. vice versa, if change first line 16 milliseconds, works. appear second line executes , completes before first line, , stays visible. how can fix that?

settimeout(function(){img.style.visibility = 'visible';},23); settimeout(function(){img.style.visibility = 'hidden';},17); 

both of lines execute 1 right after other. then, later, functions you've passed settimeout called. they're called according delay gave. when give shorter delay second one, of course gets called first.

if goal have img become visible after 23 milliseconds , invisible again 17 milliseconds later, want put second call inside first.

settimeout(function(){     img.style.visibility = 'visible';     settimeout(function(){         img.style.visibility = 'hidden';     }, 17); }, 23); 

that said, remember human beings slow, clumsy creatures. :-) normal person, image never going visible, 17ms brief interval.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -