本文介绍了基于布尔值的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
发布评论