Sunday, June 7, 2009

JavaScript onmousemove Event

The onmousemove event occurs when the mouse pointer is moved.
Example:
<span id="trail" onmousemove="cursor()" onmouseout="hide()" style="visibility:visible; color:#000099; font-weight: bold;">cursor text here</span>

<div id="showhide" style="visibility:hidden">
<p>This is cursor event</p>
</div>

Javascript:
function cursor()
{
var scrollX = event.clientX + document.body.scrollLeft;
var scrollY = event.clientY + document.body.scrollTop

document.getElementById('showhide').style.visibility="visible"
document.getElementById('showhide').style.position="absolute"
document.getElementById('showhide').style.left=scrollX;
document.getElementById('showhide').style.top=scrollY;
}
function hide()
{
document.getElementById('showhide').style.visibility="hidden"
}