www.webdeveloper.com
Results 1 to 3 of 3

Thread: Style.Left += n

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Style.Left += n

    What's the problem with:
    Code:
    document.img1.style.left += 20
    ? Thanks!

  2. #2
    Join Date
    Oct 2003
    Location
    Andover, UK
    Posts
    947
    That will result in NaN, i.e. not a number. Kill the 'px'.

    Code:
    document.img1.style.left = parseInt(document.img1.style.left) + 20 + "px";
    This assumes that style.left is set, and not empty. If it's empty, it will fail, and you'll need a condition that checks this (and uses 0 for the calculation if so) or gets the left some other way, e.g. .offsetLeft).

  3. #3
    Join Date
    Nov 2009
    Posts
    2
    You're good.

    Thanks.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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