I’ve been doing some Googling to find an answer to this, but I’ve had no luck. It could be because I’m a bit of an amateur and I don’t know the proper terms to search for, but maybe someone here can steer me in the right direction or help me out.
Anyway, I’m looking for a way to get a div to randomly, smoothly move around a page. There will be a background color, then this image which I want to seemingly randomly, infinitely move around the page. Much like the background of a DVD player’s home screen where “DVD” is just floating around.
Starting point of the div doesn’t matter, nor does the ending point. It just needs to randomly move around the page for the duration a user is on that page.
I’ve got decent HTML and CSS skills, very basic JS skills, and some experience implementing jQuery. Ideally, I’d like something which I can implement myself.
Thanks in advance!!!
The basic premise is to generate positional values, and use jquery’s animate() function to move the div. The calculation of the next position is simple, you just need a bit of math. Here’s a very basic jsfiddle i just knocked up. It could do with possibly a delay timer, a dynamically calculating speed based on how far its got too move e.c.t. But it gives you a start point i hope.
http://jsfiddle.net/Xw29r/
Updated example code with speed modifier:
http://jsfiddle.net/Xw29r/15/
For some reason this is still getting some attention, so here’s an updated answer that uses CSS transitions which should be much smoother.
http://jsfiddle.net/bf9nv1q6/