Javascript Jquery .show() 不显示隐藏可见性的 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7204494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery .show() not revealing a div with visibility of hidden
提问by ChrisCa
Basic jQuery question:
基本的 jQuery 问题:
I am trying to reveal a div
that has been marked as hidden using jQuery. But am not quite getting it
我试图揭示一个div
已使用 jQuery 标记为隐藏的。但我不太明白
I've created a JSFiddle here: http://jsfiddle.net/VwjxJ/
我在这里创建了一个 JSFiddle:http: //jsfiddle.net/VwjxJ/
Basically, I want to use style="visibility: hidden;"
rather than style="display: none;"
as I want the space of the hidden element to be maintained
基本上,我想使用style="visibility: hidden;"
而不是style="display: none;"
因为我希望保留隐藏元素的空间
Have tried using show()
, fadeIn()
etc but neither work (they do for style="display: none;"
)
使用试过show()
,fadeIn()
等,但没有工作(他们为做style="display: none;"
)
what am I doing wrong?
我究竟做错了什么?
回答by Muhammad Usman
If you have hidden it with visibility:hidden
then you can show it with jQuery by
如果你已经隐藏了它,visibility:hidden
那么你可以通过 jQuery 显示它
$(".Deposit").css('visibility', 'visible');
And in the fiddle you are missing jQuery. Here is a demo:http://jsfiddle.net/9Z6nt/20/
在小提琴中,您缺少 jQuery。这是一个演示:http : //jsfiddle.net/9Z6nt/20/
回答by Polymorphix
According to JQuery documentation .show()
"is roughly equivalent to calling .css('display', 'block')
, except that the display property is restored to whatever it was initially."
Set the style explicitly instead. You could use a CSS class
根据 JQuery 文档,.show()
“大致相当于调用.css('display', 'block')
,只是显示属性恢复到最初的状态。” 而是显式设置样式。您可以使用 CSS 类
.hidden{
visibility: hidden;
}
.shown{
visibility: visible;
}
and set is using
和 set 正在使用
$("#yourdiv").removeClass("hidden").addClass("shown");
回答by MJ Vakili
If you want the space of the hidden element to be maintained, use opacity.
如果要保留隐藏元素的空间,请使用不透明度。
i.e:
IE:
$('div').fadeTo(500,1) //show
$('div').fadeTo(500,0) //hide
for example:
例如:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style='opacity:0'>
Test opacity
</div>
<button onclick="$('div').fadeTo(500,1);">Show</button>
<button onclick="$('div').fadeTo(500,0);">Hide</button>
回答by sushil bharwani
Hey man your fiddle is working just choose framework jQuery on the fiddle. If its visibility hidden then change the css visibility property to visible.
嘿伙计,您的小提琴正在工作,只需在小提琴上选择框架 jQuery。如果其可见性隐藏,则将 css 可见性属性更改为可见。
(".Deposit").css('visibility','visible');
(".Deposit").css('visibility','visible');
回答by George Matiashvili
here we go :)
开始了 :)
$(".Deposit").show();
$(".Deposit").fadeOut(500,function(){
$(this).css({"display":"block","visibility":"hidden"});
});
回答by George Matiashvili
$(".Deposit").show();
$(".Deposit").fadeTo(500,0);