Monday 15 September 2014

javascript - Using stop() with jquery to launch a function only one time -



javascript - Using stop() with jquery to launch a function only one time -

i don't understand utilize of stop() element in jquery. in example, seek open div when user launch myfunction function (for illustration clicking on trigger) if click several time, #mydiv desapears anyway, without waiting 3 seconds, because close 3 sec after first click.

function myfunction(hello) { $( "#mycontener" ).html( hello ); $( "#mydiv" ).stop( true, true ).slidedown( 250, function() { settimeout(function() { $("#mydiv").slideup( 250 ); }, 3000); }); };

is clear plenty ? thanks

you need clear timeout prevent happening on future calls. this:

(function () { var handle; function myfunction(hello) { cleartimeout(handle); $("#mycontener").html(hello); $("#mydiv").stop(true, true).slidedown(250, function () { handle = settimeout(function () { $("#mydiv").slideup(250); }, 3000); }); } window.myfunction = myfunction; })();

javascript jquery

No comments:

Post a Comment