dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: continuously change left margin on mouseover

  1. #1
    Join Date
    Nov 2009
    Posts
    28

    continuously change left margin on mouseover

    Hi, I would like to write a script that continuously changes the left margin of a div while the user hovers over another div. onmouseover would start changing the margin and onmouseout would stop it. The margin should change by subtracting 10px to the current margin so that it would continuously decrease. I'm sure it's something simple that I'm missing. The value for the left margin is in document.getElementById('div').style.marginLeft.

    Thanks,

    gecko

  2. #2
    Join Date
    Aug 2007
    Location
    New Jersey, US
    Posts
    1,779
    HTML Code:
    onmouseover="document.getElementById('yourDiv').style.marginLeft='-10px';"
    onmouseout="document.getElementById('yourDiv').style.marginLeft='0';"
    should work

  3. #3
    Join Date
    Nov 2009
    Posts
    28
    Ok, this changes the left margin to -10px onmouseover and to 0px onmouseout. That works fine, but what I'm looking for is a way to continuously subtract 10px from the left margin while the mouse is over the other div. In other words, have it go from 0px to -10px to -20px to -30px... and then stay at -30px when the mouse is moved out of the div. Thanks for the quick reply.

  4. #4
    Join Date
    Nov 2009
    Posts
    28
    I probably should have posted this in the Javascript forum. Mods?

  5. #5
    Join Date
    Aug 2007
    Location
    New Jersey, US
    Posts
    1,779
    Oh, gotcha. I'm not great at JS. I won't be much help here. Sorry.
    Good luck with it!

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