码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-08-12 17:53:14      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

 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;
                };

 

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

标签:

原文地址:http://www.cnblogs.com/chenjinxinlove/p/5765730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!