基于布尔值的fadeIn / fadeOut [英] fadeIn / fadeOut based on a boolean
本文介绍了基于布尔值的fadeIn / fadeOut的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我是否真的要写:
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);
我见过fadeToggle,但它不接受布尔状态参数。
I've seen fadeToggle, but it doesn't accept a boolean status parameter.
推荐答案
不,没有,但你可以这样做:
No, there is not, but you can make one like that:
jQuery.fn.fadeInOrOut = function(status){
return status ? this.fadeIn() : this.fadeOut();
}
然后像这样调用它(参见这个jsfiddle 证明):
and then call it like that (see this jsfiddle for a proof):
$('#status-image-' + id).fadeInOrOut(status);
这是你想要的吗?
这篇关于基于布尔值的fadeIn / fadeOut的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文