基于布尔值的fadeIn / fadeOut

编程入门 行业动态 更新时间:2024-10-28 15:25:57
本文介绍了基于布尔值的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

本文发布于:2023-10-26 20:45:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布尔值   fadeIn   fadeOut

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!