Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Javascript Animation Help

Name: Anonymous 2010-12-13 9:05

Javascript

I'm trying to make a picture bounce between 50px x value, to 200 pixels left of the right boundary. (img is 150px wide, so this would work for top/left corner)

Here is my code:

<script>
var y = 0;
var x = 50;
width = document.body.clientWidth;
var stophere = width - 200;

function animate()
{
while (x < stophere)
{
x += 5;
shiftTo(x, y, 2);
}
}

I have other functions that make the animation actually occur, which it does, but only when I don't use the while statement. Am I doing something wrong with determining the width and setting it to a var?

What I'm trying to do:
Picture with top/left corner at (0,50) ---> Translates right until width - 200

In theory this should be easy...javascript fucking sucks

Name: Anonymous 2010-12-13 22:49

>>1,9
- Global variables
- Missing 'var' declaration
- Using == instead of ===
- Using a loop for animation instead of a timer

Please leave now

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List