I was wondering if I really have to write:
if (status) {
$('#status-image-' + id).fadeIn();
} else {
$('#status-image-' + id).fadeOut();
}
or there is a function to which I can provide my boolean status, something like:
$('#status-image-' + id).fade(status);
I've seen fadeToggle, but it doesn't accept a boolean status parameter.
The jQuery fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out. Syntax: $(selector).fadeToggle(speed,callback);
Definition and Usage. The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeIn() method.
fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.
No, there is not, but you can make one like that:
jQuery.fn.fadeInOrOut = function(status){
return status ? this.fadeIn() : this.fadeOut();
}
and then call it like that (see this jsfiddle for a proof):
$('#status-image-' + id).fadeInOrOut(status);
Is it what you wanted?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With