i have this action after click:
remote_top.on('click',function(){
if (program_changer_block.css('display','block')){
var g_timer = null;
clearTimeout(g_timer);
setTimeout(function(){
program_changer_block.fadeOut();
}, 5100);
}
else if (program_changer_block.css('display','none')){
setTimeout(function(){
program_changer_block.fadeIn();
}, 300);
}
});
What i’m trying to do is clear timeout after each click. Now after some fast clicks my blocks hide after 5100ms calculated from the first click. How to restart this timeout after each click? Something is wrong, can you help me?
The
setTimeout()function returns the timeout ID. Just store it in yourg_timervariable and also make it global: