• 在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 };
            }
  • 相关阅读:
    jquery练习(赋予属性值)
    jquery练习
    jquery表单对象属性选择器
    jquery表单选择器
    jquery子元素选择器
    jquery属性选择器(同时匹配多个条件)
    jquery属性选择器
    jquery属性选择器(匹配具有指定属性的元素)
    jquery可见性选择器(综合)
    方法的递归
  • 原文地址:https://www.cnblogs.com/wangbogo/p/2651986.html
Copyright © 2020-2023  润新知