Reputation: 14464
I'm creating an online game using jQuery. Due to lot of fade effect for slower computers I did an option that sets jQuery.fx.off = true;
That caused a problem with this code:
$('<div>'+msg+'</div>').fadeOut(5000,function({$(this).remove()}).appendTo('#msg');
This code display messages in the #msg div, then after 5 seconds message is gone. There can be many messages and they can be added in any time. When jQuery.fx.off = true;
message won't appear because fadeOut is done instantly :( What I need is something like $('#id').delay(5000).remove()
when fx.off is true.
I was looking for it in jQuery's help, but nothing found.
Upvotes: 1
Views: 338
Reputation: 26227
This may or may not be an acceptable solution to your problem, but you could create a new JQuery function called maybeFadeOut or something.
jQuery.fn.maybeFadeOut = function (time, fun) {
if (slowComputer) {
setTimeout(function () {
$(this).remove();
if (fun) fun(); // Optionally run the callback function.
}, time);
return $(this);
} else {
return $(this).fadeOut(5000, function () { $(this).remove; });
}
};
Upvotes: 2