1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
function getEvent() //同时兼容ie和ff的写法 { if (document.all) return window.event; func = getEvent.caller; while (func != null) { var arg0 = func.arguments[0]; if (arg0) { if ((arg0.constructor == Event '' arg0.constructor == MouseEvent) '' (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) { return arg0; } } func = func.caller; } return null; } var __is_ff = (navigator.userAgent.indexOf("Firefox") != -1); function getMouseLocation() { var e = getEvent(); var mouseX = 0; var mouseY = 0; if (__is_ff) { mouseX = e.layerX + document.body.scrollLeft; mouseY = e.layerY + document.body.scrollLeft; } else { mouseX = e.x + document.body.scrollLeft; mouseY = e.y + document.body.scrollTop; } return { x: mouseX, y: mouseY }; } function show() { var test = getMouseLocation(); alert(test.x + ":" + test.y); }
|
js获取鼠标当前所在页面位置 - wboweb - 博客园.