Click to See Complete Forum and Search --> : continuously change left margin on mouseover


gecko91
11-06-2009, 10:06 AM
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

dtm32236
11-06-2009, 10:46 AM
onmouseover="document.getElementById('yourDiv').style.marginLeft='-10px';"
onmouseout="document.getElementById('yourDiv').style.marginLeft='0';"

should work

gecko91
11-06-2009, 10:53 AM
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.

gecko91
11-06-2009, 11:39 AM
I probably should have posted this in the Javascript forum. Mods?

dtm32236
11-06-2009, 12:55 PM
Oh, gotcha. I'm not great at JS. I won't be much help here. Sorry.
Good luck with it!