Ok, I know how to animate div's and loop the animation and stuff but this really got on my nerves, I want to animate a div to left:0;
and then to right:0;
and loop the animation and IT WILL NOT WORK like this...Why is that?
How do I do this?..
PS: Apparently jquery can't animate an absolute container from left:0 to right:o...but how can I get the desired animation?
Example:
Something like this will not work...:
$(document).ready(function() {
function animateMydiv() {
$('#mydiv').animate({'left':'0px'},6000).animate({'right':'0px'},6000, animateMydiv);
}
animateMydiv();
});
Here is the jsfiddle.
As far as I understand positioning in CSS, you can't have both a
right
and aleft
value set at the same time.So I would propose the follow. Just move it to the end of the document minus the width of the element:
Check out the fiddle: http://jsfiddle.net/bc927afp/1/
And if you want it to be endless, leave the function as you had in your example:
$('#mydiv').animate({'left': width + 'px'}, 6000).animate({'left': '0px'}, 6000, animateMydiv);