Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery.animate() moving divs at different speeds on some browsers
    text
    copied!<p>I recently started using JQuery and created a little slider to display logos of website sponsors and such. It seemed to be working properly for me using Firefox. I decided to load up the site in Chrome and it behaves rather strange. The animation seems fine until the first div(the slider is split into two divs, so that the first can move to the end once it has completed it's pass through the masking div) enters the screen for the second(and each concurrent) pass. The first div seems to move more rapidly, and overtakes the second div. Any ideas what would cause this? It only seems to happen in Chrome and Safari. IE worked even!</p> <pre><code>$(document).ready(function () { var s1 = $("div[name=s1]"); var s2 = $("div[name=s2]"); var release = 0; var speed = 75; //px per sec var interval = 100; //milliseconds per animation var origSpeed = speed; function slide() { release = 1 - release; if (release == 0) { return; } distance = "+=" + (parseInt(s1.width(), 10) + parseInt(s2.width(), 10)) + "px"; if ((-1 * parseInt(s1.css("left"), 10)) &gt; parseInt(s1.width(), 10)) { s1.css({left: distance}); } if ((-1 * parseInt(s2.css("left"), 10)) &gt; (parseInt(s1.width(), 10) + parseInt(s2.width(), 10))) { s2.css({left: distance}); } slide_again(); } function slide_again() { $("div[id=slider]").animate({left: "-=" + interval * (speed / 1000) + "px"}, interval, "linear", slide); } $("div[id=slider]").hover(function() { speed = 0; }, function() { speed = origSpeed; }); slide(); }); </code></pre> <p>You can see it in action <a href="http://www.racefactorygaming.com/test/slidertest.html" rel="nofollow">here</a></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