
JS Tip
ezjQuery » JS Tip » JS tip »» Prev | Next
ezjQuery » JS Tip » Plugins
Add Comment
Subject: mouse position with jQuery
Author: EZjquery
Tag: Utilities
Post Time: 2008/05/15 10:24:18
Email Address: jquerylearning@gmail.com
mouse position with jQuery
Old javascript way
Code
function doSomething(e)
{
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY)
{
posx = e.clientX;
posy = e.clientY;
}
// posx and posy contain the mouse position relative to the document
// Do something with this information
}
jQuery way
Code
$(document).mousemove(function(e){
var posx =e.pageX;
var posy=e.pageY;
// Do something with this information
});
//Tested with IE7 and Firefox 2.0
ezjQuery » JS Tip » JS tip »» Prev | Next
ezjQuery » JS Tip » Plugins
Add Comment»Add comment
Top