Moving the pin.
Posted: Wed Oct 11, 2006 12:15 pm
I'm trying to move this element I have with ID of "pin".
With these functions in the head:
It's not doing what I want it to. I want the pin to move horizontally when clicked on, which it does. But then I want it to move only within certain boundaries which I set, which it doesn't.
I don't know what I'm doing wrong the code isn't doing what I commanded it to. It seems to make perfect sense when you look at the code, it's just not stopping at 40 and 100.
Thanks for reading my post. I'd appreciate any help on this matter.
Code: Select all
<a href="" id="pin" onmousedown="return pin_onmousedown(event)" onclick="return false" style="position:absolute;">
<img src="images/Pin.png" border="0" />
</a>Code: Select all
function pin_onmousedown(e)
{
if (document.getElementById("pin").style.left > 100)
{
document.getElementById("pin").style.left = 100;
}
else if (document.getElementById("pin").style.left < 40)
{
document.getElementById("pin").style.left = 40;
}
else
{
document.getElementById("pin").style.left = e.clientX - 6;
}
document.onmousemove = pin_onmousedown;
document.onmouseup = pin_onmouseup;
return false;
}
function pin_onmouseup()
{
document.onmousemove = new Function("return false");
}I don't know what I'm doing wrong the code isn't doing what I commanded it to. It seems to make perfect sense when you look at the code, it's just not stopping at 40 and 100.
Thanks for reading my post. I'd appreciate any help on this matter.