JQuery 检查是否显示 Div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3282887/
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 Check to See if Div is Shown
提问by Jason
This is what I am ultimately trying to achieve:
这就是我最终想要实现的目标:
//When the user clicks the liveshow button this happens
$(".liveshow-button").live('click', function() {
if ($(".liveshowDiv2").css('display') == 'none') {
$(".liveshowDiv2").fadeOut(ifadeOutSpeed, function() {
$('#wrapper-div').animate({ height: $('.liveshowDiv1').height() + "px" }, iresizeSpeed, function() {
$('.liveshowDiv1').fadeIn(ifadeInSpeed, function() {
});
});
});
}
else {
alert('This never gets displayed');
$(".liveshowDiv1").slideUp('fast');
}
});
Basically I want to toggle between liveShowDiv1 being displayed and hidden when you click this button. But since other things on the page can make liveShowDiv1 hidden, I can't just make a toggle function to do this. I have to check somehow to see if liveShowDiv1 is being displayed or not.
基本上,当您单击此按钮时,我想在显示和隐藏 liveShowDiv1 之间切换。但是由于页面上的其他内容可以使 liveShowDiv1 隐藏,因此我不能仅使用切换功能来执行此操作。我必须以某种方式检查是否正在显示 liveShowDiv1。
When it not displayed: display = none
不显示时:display = none
When it is showing display is not in the style tag at all
当它显示显示根本不在样式标签中时
How can I tell in JQuery when this div is displayed?
如何在 JQuery 中判断何时显示此 div?
回答by meder omuraliev
if ( $(this).is(':visible') )
should work for this relatively simple show/hide.
if ( $(this).is(':visible') )
应该适用于这个相对简单的显示/隐藏。
回答by Shafiqul Islam
Sometime need to check that div is block or none. We can do this very easily . This is simple code . here id = "test"
-> for testing purpose if you use class = "test"
then need to update code
For checking Block or visible then use this for your select test
is id
有时需要检查 div 是块还是无。我们可以很容易地做到这一点。这是简单的代码。在这里id = "test"
- >用于测试目的,如果使用class = "test"
则需要更新代码对于检查中的块或可见然后使用此为您的选择test
就是id
1. if ($('#test').is(':visible')) {}
2. if ($('#test').css('display') == 'block'){}
3. if ($('#test').not(':hidden')){}
if your selector is class
then
如果你的选择是class
,然后
1. if ($('.test').is(':visible')) {}
or
或者
1. if ($(your_element).is(':visible')) {}
same other
同其他
For checking none or hide then use this code if your selector
is id
要检查 none 或 hide 如果您selector
是,请使用此代码id
1. if ($('#test').not(':visible')){}
2. if (!$('#test').is(':visible')){}
3. if ($('#test').css('display') == 'none'){}
4. if ($('#test').is(':hidden')){}
if your selector is class then use this
如果您的选择器是类然后使用它
1. if ($('.test').not(':visible')){}
or
或者
1. if ($(your_element).not(':visible')){}
hope it will help you
希望它会帮助你
回答by Ali Aboussebaba
You can try this:
你可以试试这个:
$(your_element).is(":visible")
Example;
例子;
if ($('#element_id').is(":visible") ) {
// do something
}
回答by Abhijit
You can use $(element).is(":visible")
to check if the element is visible
您可以使用$(element).is(":visible")
来检查元素是否可见