Note that there are some explanatory texts on larger screens.

plurals
  1. POUpgrading to jQuery 1.5 has broken my code
    text
    copied!<p>I have the following code to make some parallax niceness which is mapped to the scroll bar. It moves both the background position of the section and any elements in the section classed "mover"</p> <p>It works fine with jQuery 1.4.x but when we upgraded to 1.5.2 the elements don't quite get back to their original positions</p> <p>Does anyone know what changes in 1.5 would cause this?</p> <pre><code>var lastScrollTop = 0 var scrollTop = 0 $(window).scroll(function() { scrollTop = $(window).scrollTop(); var move = lastScrollTop - scrollTop; lastScrollTop = scrollTop; $('.mover').each(function(i, element){ element = $(element); if(!belowTheFold(element)){ var currentPos = parseInt(element.css("top")); var speed = $(this).attr('data-scroll-speed'); var pos = currentPos + (move*speed); element.css('top', pos); } }); $('.background-mover').each(function(i,element){ element = $(element); if(!belowTheFold(element)){ var currentPos = parseInt(element.css("background-position-y")); var speed = element.attr('data-scroll-speed'); var pos = currentPos + (move*speed); element.css('background-position-y', pos); } }); }); function belowTheFold(element){ var fold = $(window).height() + $(window).scrollTop(); return fold &lt;= element.offset().top; } </code></pre> <p>HTML:</p> <pre><code> &lt;section class="background-mover" data-scroll-speed="0.1" style="background:url(images/background.jpg) no-repeat; /*background-size:cover;*/ "&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.5" style="top:410px; left:120px; "&gt;Places&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.2" style="top:200px; left:480px; "&gt;Nature&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.3" style="top:350px; left:650px; "&gt;Landscape&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.8" style="top:580px; left:380px; "&gt;Adventure&lt;/a&gt; &lt;/section&gt; &lt;section class="background-mover" data-scroll-speed="0.2" style="background:url('images/background-2.jpg') no-repeat; height:630px; "&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.2" style="top:250px; left:90px; "&gt;Getting Around&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.5" style="top:420px; left:500px; "&gt;Events&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.3" style="top:640px; left:470px; "&gt;Accomodation&lt;/a&gt; &lt;/section&gt; &lt;section class="background-mover" data-scroll-speed="0" style="background:url(images/background-3.jpg) no-repeat; /*background-size:cover;*/ height:1200px; "&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.5" style="top:190px; left:300px; "&gt;Culture&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.1" style="top:390px; left:90px; "&gt;Must Do's&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.5" style="top:530px; left:600px; "&gt;Getting Here&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.2" style="top:680px; left:110px; "&gt;History&lt;/a&gt; &lt;a href="#" class="tag mover" data-scroll-speed="0.8" style="top:830px; left:590px; "&gt;Facts&lt;/a&gt; &lt;/section&gt; </code></pre>
 

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