js鼠标位置获取 jquery版
function getScrollLeft() {
var d = document;
return window.pageXOffset || d.documentElement.scrollLeft || d.body.scrollLeft;
};
function getScrollTop() {
var d = document;
return window.pageYOffset || d.documentElement.scrollTop || d.body.scrollTop;
};
var xy = {x:0, y:0};
// 监听当前网页的 mousemove 事件以获得鼠标的实时坐标
$(document).mousemove(function(e){
e = window.event || e;
xy.x = e.clientX;
xy.y = e.clientY;
});
function getMousePosition(){
return {
x : getScrollLeft() + xy.x,
y : getScrollTop() + xy.y
};
};
$(document).mousedown(function (){
var pos = getMousePosition();
alert("x:"+pos.x+", y:"+pos.y);
});
var d = document;
return window.pageXOffset || d.documentElement.scrollLeft || d.body.scrollLeft;
};
function getScrollTop() {
var d = document;
return window.pageYOffset || d.documentElement.scrollTop || d.body.scrollTop;
};
var xy = {x:0, y:0};
// 监听当前网页的 mousemove 事件以获得鼠标的实时坐标
$(document).mousemove(function(e){
e = window.event || e;
xy.x = e.clientX;
xy.y = e.clientY;
});
function getMousePosition(){
return {
x : getScrollLeft() + xy.x,
y : getScrollTop() + xy.y
};
};
$(document).mousedown(function (){
var pos = getMousePosition();
alert("x:"+pos.x+", y:"+pos.y);
});