document.compatMode属性和获取鼠标的位置

 document.compatMode属性

document.compatMode用来判断当前浏览器采用的渲染方式。

官方解释:

BackCompat:标准兼容模式关闭。
CSS1Compat:标准兼容模式开启。

当document.compatMode等于BackCompat时,浏览器客户区宽度是document.body.clientWidth;
当document.compatMode等于CSS1Compat时,浏览器客户区宽度是document.documentElement.clientWidth。

//获取鼠标的位置
getMousePoint = function (_e) {
                    var _body = document.body,
                            _left = 0,
                            _top = 0;
                    if(typeof window.pageXOffset != 'undefined'){
                        _left = window.pageXOffset;
                        _top = window.pageYOffset;
                    }
                    else if(typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat'){
                        _left = document.documentElement.scrollLeft;
                        _top = document.documentElement.scrollTop;
                    }
                    else if(typeof _body != 'undefined'){
                        _left = _body.scrollLeft;
                        _top = _body.scrollTop;
                    }
                    _left += _e.clientX;
                    _top += _e.clientY;

                    _mousepos.left = _left;
                    _mousepos.top = _top;

                    return _mousepos;
                };

 

转载于:https://www.cnblogs.com/chenjinxinlove/p/5765730.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值