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

Jquery判断是不是移动设备浏览

时间:2015-06-03 17:16:55      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

首先,只判断是否是用移动设备浏览的:

// Mobile 这里是只有不再移动设备上访问时,才给相应元素加上 mouseenter  和  mouseleave  事件。

if (!navigator.userAgent.match(/mobile/i)) {

    $(‘.nav-dots span‘).mouseenter(function() {
        $(this).css(‘background-color‘, ‘rgba(0, 0, 0, 0.2) !important‘);
    });
    
    $(‘.nav-dots span‘).mouseleave(function() {
        $(this).css(‘background-color‘, ‘rgba(255, 255, 255, 0.2) !important‘);
    });
    
}

 




---------------------------------------------------------------------------------------------------------

第二,需要得到详细的移动设备的类型:

$(document).ready(function() {
    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i) ? true : false;
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i) ? true : false;
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i) ? true : false;
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
        }
    };
    if (isMobile.any()) {
        $(‘.main_header‘).hide();
    }
});

 

Jquery判断是不是移动设备浏览

标签:

原文地址:http://www.cnblogs.com/bigdesign/p/4549372.html

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