views:

646

answers:

3

I am trying to make a webpage that uses a moving div that slowly moves to the left. There is also another div that moves on top of it to the right that gives a 3D effect (but that's beside the point).

What I am trying to do right now has made a 7000px wide div that slowly moves to the left (animating the "right" property of CSS with jQuery animate()), but after it's all moved by, the animation ends.

Is there a way to make the div an infinite width or at least cause it to go back to the beginning (much like a grocery store checkout moving belt thing) so the animation never stops?

I am thinking this requires a few seperate divs, each once it reaches its end, goes back, but I can't figure out how to do that as I am a beginner jQuery developer.

+2  A: 

UPDATE

Taking in account your example at http://nth.brandonwang.org/stuhf2/simpleindex.html you can fix it just by adding a callback at the end, your script must be like this:

$(document).ready(function() {
    animateRight ();
    animateLeft ();
});

function animateRight ()
{
    $('#lightright').css ("left", "100%");
    $('#lightright').animate({left:'0%'},1500, "", animateRight);
}

function animateLeft ()
{
    $('#lightleft').css ("right", "100%");
    $('#lightleft').animate({right:'0%'},1600, animateLeft);
}

Basically we just reset the animated css property and start de animation effect, the animation duration is faster in this code just to help to see the effect.

Hope that it helps you

AlbertEin
I don't get how exactly that works; you can see my work here: nth.brandonwang.org/stuhf2/If you wait long enough, you'll notice that the movement disappears as the divs move off the screen.
Brandon Wang
Ok, i've just made a bran new demo with just what you need, i hope it helps you
AlbertEin
What does deltaX and deltaT do?
Brandon Wang
deltaX and deltaY defines how fast it'll scroll, the animation is defines as "The div moves deltaX pixels to the left every deltaY milliseconds"
AlbertEin
Sorry to bother you again, and I know I must seem incredibly stupid but I still can't figure out how to implement this... could you look at my code (the link nth.brandonwang.org/stuhf2) and tell me how to implement it? Thank you SO much.
Brandon Wang
Could you put together a simpler page with just the animation effect so i can take a look at it?
AlbertEin
http://nth.brandonwang.org/stuhf2/simpleindex.html
Brandon Wang
I updated the post with the change to the script that you need, it seems that you don't need my previous effect
AlbertEin
IT WORKS! Thanks!
Brandon Wang
@Brandon Wang: You're welcome
AlbertEin
+2  A: 

You could look into using the jQuery marquee plugin:

http://remysharp.com/demo/marquee.html
http://remysharp.com/2008/09/10/the-silky-smooth-marquee/

Dan Herbert
That seems like a good idea!
Brandon Wang
+1  A: 

Are you trying to implement parallax in your page? There are a couple of plugins for handling this.

http://plugins.jquery.com/project/jparallax http://plugins.jquery.com/project/jquery-parallax http://en.wikipedia.org/wiki/Parallax

micmcg