views:

46

answers:

2

Hello,

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

+5  A: 
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

Val
yes this is good, but i want to check it continuously.. how to check it ?
Aakash Chakravarthy
use a setInterval or setTimeout...check Edit 2 in a minute
Val
Dont pass string, do like this: `setTimeout(checkVisibility,1000)`/
Cipi
thnx @cipi I have been working on regex recently and my head is all over the place :)
Val
A: 

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();}
Cipi