www.webdeveloper.com
Results 1 to 5 of 5

Thread: Javascript auto incrementing CSS in FF3

  1. #1
    Join Date
    Mar 2007
    Posts
    15

    Javascript auto incrementing CSS in FF3

    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?

    Thanks,

    Justin

  2. #2
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    pixelLeft is an IE specific property. For Firefox and all other browsers you'd need to use style.left. Something like this might work

    Code:
    var moveX = parseInt(document.getElementById('someId').style.left);
    moveX -= 2;
    document.getElementById('someId').style.left = (moveX)+'px';

  3. #3
    Join Date
    Mar 2007
    Posts
    15
    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.

  4. #4
    Join Date
    Apr 2006
    Location
    Houston
    Posts
    1,374
    Please post the script you are using, or at least a working example of the problem.

  5. #5
    Join Date
    Mar 2007
    Posts
    15
    I apologize, what you suggested worked. I had forgotten to change the condition in my if statement (to check to see if it was < 0) after trying what you suggested, causing my javascript to stop. Thank you so much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles