Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery function don't get correctly variable
    text
    copied!<p>I have a function that is called many times when the window browser is resized or when I click on some elements.</p> <p>This function calculate the correct width of a container based on children items width (variable colW). It seems that when my function is execute, the colW variable is not correctly get or it's not the right width (it's the previous calculated width). This colW variable is calculated in function of the window size.</p> <p>If I put an alert(colW) everything works fine. In this case the variable is correctly get.</p> <p>I don't know how to resolve this problem. Maybe I didn't correctly set my variable or I need to be sure that the previous fonction is done before to execute the next function.</p> <p>Here my script:</p> <pre><code>function checkSly() { //alert(colW); numNormal = $('.element:not(.square,.wide,.tall,.isotope-hidden)').length; numSquare = $('.element.square:not(.isotope-hidden)').length; numWide = $('.element.wide:not(.isotope-hidden)').length; numTall = $('.element.tall:not(.isotope-hidden)').length; totalelement = numNormal+numSquare*4+numWide*2+numTall+3; columnswidth = Math.ceil((totalelement)/HIsotopeRows)*colW; slideewidth = Math.round(columnswidth); $('#container').width(slideewidth); frame.reload(); } </code></pre> <p><strong>EDIT</strong></p> <p>if I add a setTimeout, the variable have the time to be calculated (because the colW width animate some elements) and it works great :</p> <pre><code> function checkSly() { setTimeout(function() { numNormal = $('.element:not(.square,.wide,.tall,.isotope-hidden)').length; numSquare = $('.element.square:not(.isotope-hidden)').length; numWide = $('.element.wide:not(.isotope-hidden)').length; numTall = $('.element.tall:not(.isotope-hidden)').length; totalelement = numNormal+numSquare*4+numWide*2+numTall+3; columnswidth = Math.ceil((totalelement)/HIsotopeRows)*colW; slideewidth = Math.round(columnswidth); $('#container').width(slideewidth); frame.reload(); }, 300); } </code></pre> <p>I think I need to wait that all animations are completed before to call checkSly() function... Is there a way to wait animation are finished before execute a function? Because with setTimeout it will not works all the time (because animation depend on browser type, CPU and others things....)</p> <p>Sorry for my english, I m french.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload