javascript - Return function multiple times instead of one time using .fadeOut(); -
i don't know if suppoused this, guess is...
i thought @ first may wrong whole script , managed make new file on localhost , test fadeout();
function.
apparently returned function twice again went jsfiddle check happen there. , same thing happened. in case console.log();
returned twice.
- what did , trying ?
well want return specified function, or in fiddle sample, specified console.log();
once. fadingout multiple elements (two, exact).
is there way that, instead of duplicating each element fadeout @ same time ?
sample return console.log(); twice.
settimeout(function () { $( ".one, .two" ).fadeout(300, function () { console.log("return function!"); }); }, 2000);
sample return console.log(); once.
settimeout(function () { $( ".one" ).fadeout(300); $( ".two" ).fadeout(300, function () { console.log("return function!"); }); }, 2000);
fiddle preview: fiddle redirect
there 2 elements in collection, fadeout
called twice, yes, it's supposed that.
you can have callback fire once regardless of number of elements in collection using returned promise animation , $.when
, $.then
settimeout(function () { $.when( $( ".one, .two" ).fadeout(300) ).then(function () { console.log("return function!"); }); }, 2000);
Comments
Post a Comment