相当于jQuery .hide()设置可见性:hidden [英] Equivalent of jQuery .hide() to set visibility: hidden
本文介绍了相当于jQuery .hide()设置可见性:hidden的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,有 .hide()
和 .show()
c $ c> display:none 设置。
In jQuery, there are .hide()
and .show()
methods which sets the CSS display: none
setting.
是否有一个等效函数可以设置 visibility:hidden
设置?
Is there an equivalent function which would set the visibility: hidden
setting?
我知道我可以使用 .css()
,但我喜欢。 hide()
左右。
I know I can use .css()
but I prefer some function like .hide()
or so. Thanks.
推荐答案
您可以制作自己的插件。
You could make your own plugins.
jQuery.fn.visible = function() {
return this.css('visibility', 'visible');
};
jQuery.fn.invisible = function() {
return this.css('visibility', 'hidden');
};
jQuery.fn.visibilityToggle = function() {
return this.css('visibility', function(i, visibility) {
return (visibility == 'visible') ? 'hidden' : 'visible';
});
};
如果你想重载原来的jQuery toggle $ c>,我不推荐...
If you want to overload the original jQuery toggle()
, which I don't recommend...
!(function($) {
var toggle = $.fn.toggle;
$.fn.toggle = function() {
var args = $.makeArray(arguments),
lastArg = args.pop();
if (lastArg == 'visibility') {
return this.visibilityToggle();
}
return toggle.apply(this, arguments);
};
})(jQuery);
jsFiddle 。
这篇关于相当于jQuery .hide()设置可见性:hidden的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文