S
S
Sergey2015-10-20 12:07:14
JavaScript
Sergey, 2015-10-20 12:07:14

How to execute a function in js while the layer is visible?

There is a code:

if ($('#aa_plugins_tabmsgBox').is(':visible') == true) {
      if( $('#navbar').offset().top < 0 ) {
        headfix();
      }
    }


I need to optimize it to be something like
while ($('#aa_plugins_tabmsgBox').is(':visible') == true) do

Is this possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Chernyshev, 2015-10-20
@delch

First $('#aa_plugins_tabmsgBox').is(':visible') returns either true or false, why compare it again? Secondly, you have some kind of script that makes it visible / invisible, hang a trigger there and subscribe to it where necessary in order to respond to a state change.

V
Vitaly Inchin ☢, 2015-10-20
@In4in

synchronously:

var aptB = $('#aa_plugins_tabmsgBox');
while(aptB.is(':visible')){
   //do
}

asynchronously:
var aptB = $('#aa_plugins_tabmsgBox');
setInterval(function(){
   if(aptB.is(':visible'))  //do
}, 1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question