Having some problems with a piece of Jquery code, well that’s where I think the problem is – On FF when the page loads after 2 seconds it animates panels from the left of the screen to the right. It looks fine without any issues but in Chrome and IE it jumps back and continues moving across.
Here is the code –
<script type="text/javascript" language="javascript">
$(function() {
// Display div slowly
$('#one').delay(2000).show('slow');
$("#one").animate({
left: '+=159'
}, 3000);
$('#two').delay(3000).show('slow');
$("#two").animate({
left: '+=159'
}, 3000);
$('#three').delay(4000).show('slow');
$("#three").animate({
left: '+=159'
}, 3000);
$('#four').delay(5000).show('slow');
$("#four").animate({
left: '+=159'
}, 3000);
});
</script>
Here is a preview of the page – http://www.visrez.com/preview/och-group/
P.S I’m not ruling out it’s a css issue…
Thanks in advance for any help!
Gearóid
The problem stems from the fact that Chrome isn’t taking into account the position (relative to the offset parent) that
divhas on the page before you start moving it. So, once animated, it has a value ofleft: 159pxwhich is relative to the body. Firefox is taking the original position into account and ends withleft: 256px.I haven’t looked into why this happens yet but here are a few things that you could do (workarounds):
Before animating figure out the position relative to the offset parent and set the CSS
topandleftattributes. Then, hopefully, the final value will be the value that you set plus 159px. Something like:Wrap
#oneTopand#oneand each other pair in a div that isposition: relative. This will set the offset parent of the animated div to theposition: relativediv. This way the +159px is relative to where the div would be in the document.