zoukankan      html  css  js  c++  java
  • 在iframe 中的页面取鼠标的位置

    function showCurrentInIfaremPosition() {
                
                var isIE = false;
                if (window.ActiveXObject) {
                    isIE = true;
                }
    

            var isIE9 = false;
            var browser = navigator.appName
            var b_version = navigator.appVersion
            var version = b_version.split(";");
            var trim_Version = version[1].replace(/[ ]/g, "");
            if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE9.0") {
              isIE9 = true;
            }

    
    

            var test = getMouseLocation();
            var CurrentX = 0;
            var CurrentY = 0;
            CurrentX = test.x;
            CurrentY = test.y;

    
    

            if (isIE9) {

              // var topbodywidth = window.top.document.body.offsetWidth; //页面宽度

              // var topbodyheight = window.top.document.body.offsetHeight; //页面高度

    var winwidth = 0;
                    var winheight = 0;
                    var paddingleft = 0;
                    var paddingtop = 0;
                    var divObjs = window.top.document.getElementById("divPanelIMOpenContacts"); //$("#divPanelIMOpenContacts");
                    if (divObjs) {
                        paddingleft = divObjs.offsetLeft;  //div距浏览器左边距
                        paddingtop = divObjs.offsetTop;   //div距浏览器上边距
                    }
    //                alert("左边距:" + paddingleft);
    //                alert("上边距:" + paddingtop);
    //                alert("鼠标相对浏览器位置X:" + CurrentX);
    //                alert("鼠标相对浏览器位置Y:" + CurrentY);
                    CurrentX = CurrentX - paddingleft;
                    CurrentY = CurrentY - (paddingtop + 30);
    //                alert("鼠标相对Iframe页面位置X:" + CurrentX);
    //                alert("鼠标相对Iframe页面位置Y:" + CurrentY);
                }
    
                var divHeight = $("#citydiv").height;
                var divCityList = document.getElementById("citydiv");
                divCityList.style.left = CurrentX - 180 + "px";
                if (b == "true") {
                    divCityList.style.top = CurrentY + 20 + "px";
                }
                else if (b == "false") {
                    divCityList.style.top = CurrentY - divHeight + "px";
                }
            }        
    
            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 };
            }
  • 相关阅读:
    webpack里CommonJS的require与ES6 的module.exports加载模块有何不同
    前端项目使用module.exports文件一定要Webpack编译吗?请问gulp可以编译这种文件吗
    Webpack之“多页面开发”最佳实战
    webpack 单页面应用实战
    也谈谈同源策略和跨域问题
    (转)Babel-现在开始使用 ES6
    webpack 配置简单说几句 ?
    Javascript 严格模式详解
    JavaScript6 新语法 let 有什么优势
    js中let和var定义变量的区别
  • 原文地址:https://www.cnblogs.com/wangbogo/p/2651986.html
Copyright © 2011-2022 走看看