[英]Jquery .show() not revealing a div with visibility of hidden
Basic jQuery question: 基本的jQuery问题:
I am trying to reveal a div
that has been marked as hidden using jQuery. 我试图揭示一个使用jQuery标记为隐藏的
div
。 But am not quite getting it 但我不太明白
I've created a JSFiddle here: http://jsfiddle.net/VwjxJ/ 我在这里创建了一个JSFiddle: http : //jsfiddle.net/VwjxJ/
Basically, I want to use style="visibility: hidden;"
基本上,我想使用
style="visibility: hidden;"
rather than style="display: none;"
而不是
style="display: none;"
as I want the space of the hidden element to be maintained 因为我希望保持隐藏元素的空间
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? 我究竟做错了什么?
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. 在小提琴中你缺少jQuery。 Here is a demo: http://jsfiddle.net/9Z6nt/20/
这是一个演示: http : //jsfiddle.net/9Z6nt/20/
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." 根据JQuery文档
.show()
“大致相当于调用.css('display', 'block')
,除了display属性恢复到最初的状态。” Set the style explicitly instead. 请改为明确设置样式。 You could use a CSS class
你可以使用CSS类
.hidden{
visibility: hidden;
}
.shown{
visibility: visible;
}
and set is using 并设置正在使用
$("#yourdiv").removeClass("hidden").addClass("shown");
If you want the space of the hidden element to be maintained, use opacity. 如果要保留隐藏元素的空间,请使用不透明度。
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>
Hey man your fiddle is working just choose framework jQuery on the fiddle. 嘿,你的小提琴正在工作只是选择框架jQuery的小提琴。 If its visibility hidden then change the css visibility property to visible.
如果隐藏其可见性,则将css可见性属性更改为可见。
(".Deposit").css('visibility','visible');
here we go :) 开始了 :)
$(".Deposit").show();
$(".Deposit").fadeOut(500,function(){
$(this).css({"display":"block","visibility":"hidden"});
});
$(".Deposit").show();
$(".Deposit").fadeTo(500,0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.