zoukankan      html  css  js  c++  java
  • js获取鼠标当前所在页面位置

           //此方法对于嵌套在一个页面A中的B页面,获取B页面的位置在IE9和其他浏览器(包括IE其他系列浏览器)下有些不同,IE9是根据浏览器来定位的,FF及其他则是根据当前页面也就是嵌套的页面来定位的(真正兼容还待改进)

        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); //Firefox 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); }
  • 相关阅读:
    ASP.Net控件基础篇
    ASP.Net
    有关于静态
    重载
    继承和多态
    面向对象的封装
    .net webform 把word转为html
    lambda 表达式 比较时间大小
    js 根据名字获取cookie 的方法
    .net 常用的命名空间和类
  • 原文地址:https://www.cnblogs.com/wangbogo/p/2651841.html
Copyright © 2011-2022 走看看