I am trying to move an image across the screen.
I'm doing this basically by a script that does this in a setInterval.
document.getElementById('someId').style.pixelLeft -= 2;
I know the setInterval is correct.....because I tested it with alerts, and this works in everything I've tried except FireFox 3. I've come to the conclusion that Firefox 3 does not refresh it's css cache.
Does anyone know a way to correct this or a possible work around?
pixelLeft is an IE specific property. For Firefox and all other browsers you'd need to use style.left. Something like this might work
var moveX = parseInt(document.getElementById('someId').style.left);
moveX -= 2;
document.getElementById('someId').style.left = (moveX)+'px';
It has the same effect as before. It only moves the image once. It would make you think that the setInterval loop only happens once, but It's really that firefox keeps grabbing the original location of the image in the css, and doing the decrementing by 2. example image left is at 100px it enters the function gets 100 for the left and then subtracts 2 from it. It should be 98 in the css now right? Well when the function runs again because of setInterval the left is again at 100 and then it subtracts 2 from it again, so it appears that the image never moves more then 2px's.
Last edited by jfluhmann; 02-04-2009 at 09:09 AM.
Please post the script you are using, or at least a working example of the problem.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)