Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are multiple problems in your code.</p> <p>First of all you use the <code>[i]</code> instead of <code>i</code> for string catenation <code>"block" + [i]</code>, when all you should write is <code>"block" + i</code>. <code>[i]</code> creates a new array of size 1; this array is soon coerced into a string, which happily is the same as i.toString() in this case; that value is then concatenated to a string.</p> <p>Secondly: instead of using IDs, you want to set a common class for all the blocks so that you can select them efficiently. Then you want to use JQuery each to loop through them instead of for.</p> <p>Thirdly - your code "setting block variables" does 1 thing only</p> <pre><code>for (j; j&lt;len; j++) { // set block vars var tem=block[j]; tem=$('#block'+[j]).offset().top; } </code></pre> <p>is equivalent to</p> <pre><code>j = len; var tem = $('#block' + (len - 1)).offset().top; </code></pre> <p>That is all the side effects it has - it does not set any "block variables".</p> <p>Instead of <code>else { if() { } }</code> write <code>else if () { }</code>.</p> <p>Move all "loop invariants" out of the for loop altogether (that is <code>$('.static_ele').hide();</code> for example is run <code>len</code> times instead of only 1.</p> <p>Lastly do not use for loop with <em>only</em> if loop variable contained within it - move the first if and last if out of the loop, and modify the for loop to run from second to second-last, to avoid the dreaded "for-case" paradigm.</p> <p>After you write your code according to these guidances then it becomes more apparent what it is trying to do and actually answering your questions would become possible</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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