标签:
示例一: x方向没有滚动
var mx=0,my=0;
function mouseMove(ev){Ev=ev||window.event;var mousePos=mouseCoords(Ev);mx=mousePos.x;my=mousePos.y;}
function mouseCoords(ev){
if(ev.pageX||ev.pageY){
return{x:ev.pageX,y:ev.pageY};
}
return{x:ev.clientX,y:ev.clientY+$(document).scrollTop()};
}
function mousePosition(ev){//返回一个类
if(ev.pageX || ev.pageY){
return {x:ev.pageX, y:ev.pageY};
}
return {
x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
y:ev.clientY + document.body.scrollTop - document.body.clientTop
}
}
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);//mousePos现在为一个类
document.getElementById(‘txt‘).value=mousePos.x+":"+mousePos.y
}
document.onmousemove = mouseMove
e.pageX;event.clientX,event.clientY,scrollLeft,clientLeft获取鼠标位置
标签:
原文地址:http://www.cnblogs.com/mawenying/p/5541374.html