Jquery检查元素是否隐藏(连续)

发布于 2024-09-11 04:20:52 字数 306 浏览 2 评论 0原文

如何检查一个元素是否立即隐藏。即如何通知元素的可见性。

就我而言,该元素是通过 slideUp 函数隐藏的。我应该立即收到有关该元素的可见性的通知。

我想到了使用 bind() 方法。但它没有类似 onHide 的事件。那么如何才能变成这样呢?任何建议都会有帮助!

编辑:

我知道可以使用is(':hidden'),但我想像addEventListener一样连续检查

How to check whether a element is made to hide at once. i.e how to notify the visibility of an element.

In my case, the element is made to hide by slideUp function. At once i should be notified about the visibility of the that element.

I got the idea of using bind() method. But it does not have a onHide like event. So how to get like this ? any suggestions will be helpful !

EDIT:

I know it is possible to use is(':hidden') but i want to check continuously like addEventListener

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎言笑 2024-09-18 04:20:52
if($('#selector').is(':visible')){
   //is visible
}else{
  //is NOT visible threfore is hidden
}

编辑
如果那不存在
那么您将必须检查不透明度/过滤器属性

,因此

if($('#selector').css('opacity')!=0){
       //is visible//or partially visible//depends on opacity
    }else{
      //is NOT visible threfore is hidden
    }

还要确保检查跨浏览器的不透明度

编辑2

function checkVisibility(){
   //put the visibility checker here
   setTimeout('checkVisibility',1000)//every 1 second...
}

注意:像这样的重复可能会减慢浏览器的速度

if($('#selector').is(':visible')){
   //is visible
}else{
  //is NOT visible threfore is hidden
}

EDIT
if that does not exist
then you will have to check for opacity/filter property

so

if($('#selector').css('opacity')!=0){
       //is visible//or partially visible//depends on opacity
    }else{
      //is NOT visible threfore is hidden
    }

also make sure you check opacity cross browser

EDIT 2

function checkVisibility(){
   //put the visibility checker here
   setTimeout('checkVisibility',1000)//every 1 second...
}

note: that repetitions like this MIGHT slow down the browser

時窥 2024-09-18 04:20:52

您可以使用 SlideUp 的回调立即知道元素何时隐藏:

function theElementIsHidden()
{
    //What to do when the slideUp animation (element hidden) is completed...
}

$("#element").slideUp(200, function(){theElementIsHidden();}

You could use slideUp's callback to know at once when the element is hiden:

function theElementIsHidden()
{
    //What to do when the slideUp animation (element hidden) is completed...
}

$("#element").slideUp(200, function(){theElementIsHidden();}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文