码迷,mamicode.com
首页 > 移动开发 > 详细

leaflet开源地图库源码 浏览器&移动设备判断(browser.js)备份

时间:2015-05-14 15:37:01      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

<script>
   var isIe = !-[1,];
  // alert(‘ie9 之前‘+isIe);
   var ie = ‘ActiveXObject‘ in window;
   //alert(‘sadsd‘+ie);
   var ie2 = !!(‘ActiveXObject‘ in window);
   //alert(‘22222‘+ie2);
   var ie3= !!window.ActiveXObject || !!("ActiveXObject" in window);   //!!window[‘ActiveXObject‘]  这个括号多了3个字符
// alert(ie3);
 
 var doc = document.documentElement;
 console.log(doc.style+‘查看支持的属性‘);
 ;(function () {

    var ua = navigator.userAgent.toLowerCase(),//var ua = navigator.userAgent.toLowerCase(); //window.navigator.userAgent,使用浏览器的UA判断,这里全部转为小写。如下图,在chrome中的判断。
        doc = document.documentElement,

        ie = ‘ActiveXObject‘ in window,

        webkit    = ua.indexOf(‘webkit‘) !== -1,  // ///retina屏幕
        phantomjs = ua.indexOf(‘phantom‘) !== -1,
        android23 = ua.search(‘android [23]‘) !== -1,   ////是否是移动端android的2.3以上版本
        chrome    = ua.indexOf(‘chrome‘) !== -1,

        mobile = typeof orientation !== ‘undefined‘,
        msPointer = navigator.msPointerEnabled && navigator.msMaxTouchPoints && !window.PointerEvent,
        pointer = (window.PointerEvent && navigator.pointerEnabled && navigator.maxTouchPoints) || msPointer,

        ie3d = ie && (‘transition‘ in doc.style),
        webkit3d = (‘WebKitCSSMatrix‘ in window) && (‘m11‘ in new window.WebKitCSSMatrix()) && !android23,
        gecko3d = ‘MozPerspective‘ in doc.style,
        opera3d = ‘OTransition‘ in doc.style;

   ///retina屏幕
    var retina = ‘devicePixelRatio‘ in window && window.devicePixelRatio > 1;

    if (!retina && ‘matchMedia‘ in window) {
        var matches = window.matchMedia(‘(min-resolution:144dpi)‘);
        retina = matches && matches.matches;
    }
    
	
	///触摸设备的验证:
    var touch = !window.L_NO_TOUCH && !phantomjs && (pointer || ‘ontouchstart‘ in window ||
            (window.DocumentTouch && document instanceof window.DocumentTouch));

    L.Browser = {
        ie: ie,
        ielt9: ie && !document.addEventListener,
        webkit: webkit,
        gecko: (ua.indexOf(‘gecko‘) !== -1) && !webkit && !window.opera && !ie,
        android: ua.indexOf(‘android‘) !== -1,
        android23: android23,
        chrome: chrome,
        safari: !chrome && ua.indexOf(‘safari‘) !== -1,

        ie3d: ie3d,
        webkit3d: webkit3d,
        gecko3d: gecko3d,
        opera3d: opera3d,
        any3d: !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d || opera3d) && !phantomjs,

        mobile: mobile,
        mobileWebkit: mobile && webkit,
        mobileWebkit3d: mobile && webkit3d,
        mobileOpera: mobile && window.opera,

        touch: !!touch,        //!!  快速转布尔值
        msPointer: !!msPointer,
        pointer: !!pointer,

        retina: !!retina
    };

}());
</script>

源码清晰完善;备份不错;

http://www.cnblogs.com/vczero/p/leaflet_3.html 参考地址

leaflet开源地图库源码 浏览器&移动设备判断(browser.js)备份

标签:

原文地址:http://www.cnblogs.com/surfaces/p/4503128.html

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