var restrictX;
var restrict>
// 滑鼠座標
function mousePosition(ev) {
return {
x : y : ev.clientY document .documentElement.scrollTop - document.documentElement.clientTop
};
}
//滑鼠事件 restrictX = mousePos.x;
restrictY = mousePos.y }5o> mouseMove;
上面的程式碼在Google和搜狐瀏覽器中取得的值會不準確,需修改,如下:
複製程式碼
程式碼如下:
var restrictX; var restrictY; var tip; // 老鼠 var tip; // 老鼠 . 🎜> var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollTop = document.document x:ev.clientX scrollLeft - document.documentElement.clientLeft,
y:ev.clientY scrollTop - document.documentElement.clientTop mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
restrictX = mousePos.x;
restrictX = mousePos.x; 🎜>document.onmousemove = mouseMove;
document.onclick = mouseMove;
複製代碼
代碼如下:
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop.兩句為,如果能取得滑鼠座標,則去前面,否則用後面的方法取得滑鼠座標,「|| 」後面的是給WebKit 核心的瀏覽器使用