Javascript - Flow side to side.

NSA

sudo apt-get thefuckout.tar.gz
Dec 9, 2011
715
86
Hi all!
I'm trying to get a div to move from the left hand side of the screen to the right, back to the left and repeat.
Now, this would be easy to do using jQuery's animate function, however... I want to be able to clone the current moving element, have it stop in its current position and the newly cloned element to carry on from where the old element was. Now, again this is fine with animate, however, with the functions set time to finish animation, once I call animate on the new element, even if it's like... 2px from the right hand side of the screen, it still takes the full length to finish. So, I tried doing it with a loop and it "kind of works". The element moves from the left, to the right and glitches out when it tries to go back to the right hand side. If anybody could take a look and see what the problem is, I'd appreciate it because I'm stuck. You can see my current code here: but please be aware, the code is messy in it's current state.

Thanks. :)
 

GarettM

Posting Freak
Aug 5, 2010
833
136
Hi all!
I'm trying to get a div to move from the left hand side of the screen to the right, back to the left and repeat.
Now, this would be easy to do using jQuery's animate function, however... I want to be able to clone the current moving element, have it stop in its current position and the newly cloned element to carry on from where the old element was. Now, again this is fine with animate, however, with the functions set time to finish animation, once I call animate on the new element, even if it's like... 2px from the right hand side of the screen, it still takes the full length to finish. So, I tried doing it with a loop and it "kind of works". The element moves from the left, to the right and glitches out when it tries to go back to the right hand side. If anybody could take a look and see what the problem is, I'd appreciate it because I'm stuck. You can see my current code here: but please be aware, the code is messy in it's current state.

Thanks. :)
When moving a rectangle across the screen make sure it stops at the screens width - rectangles width or the web page will just wrap the content witch you don't want correct?

Pseudo code
Code:
// going right
var $rectangle = $("#myRectangle");
var width = $(window).width() - $rectangle.width();
$rectangle.animate({"right": width}, "fast");
[\CODE]

This is a guess I am making :P
 

Users who are viewing this thread

Top