Mobile JS仅针对移动设备

Mobile JS仅针对移动设备,mobile,javascript,Mobile,Javascript,我正在构建一个响应性很强的网页,它有一个3列的容器,可以均匀地扩展。为了实现这一点,我使用以下JS代码: jQuery(document).ready(function($){ var inHeight = $("#wrapper").innerHeight(); $("#wrapper .col").each(function(){ $(this).height((inHeight+60)+"px"); $(this).find('.conten

我正在构建一个响应性很强的网页,它有一个3列的容器,可以均匀地扩展。为了实现这一点,我使用以下JS代码:

jQuery(document).ready(function($){
    var inHeight = $("#wrapper").innerHeight();
    $("#wrapper .col").each(function(){
        $(this).height((inHeight+60)+"px");
        $(this).find('.content').height((inHeight)+"px");
    }); 
});
演示:

现在,我需要做的是将JS更改为目标移动设备,或者删除它以使每个列独立运行

如果用户在移动设备上,如何禁用此代码?

要以移动设备(或最大宽度为X像素的更好的设备)为目标,可以使用
$(window).width()


但是代码的实际问题是:您试图使用JS使您的网站具有响应性,而您应该使用CSS媒体查询

         var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};
             if(isMobile.any()) { your code here }

谢谢你!实际上我在使用媒体查询。唯一需要JS的是这3列。关于你的代码,我不太确定该怎么处理它以及放在哪里。抱歉,我是JS中的noob:'(只需使用函数的返回值检查移动设备:
if($(window).width()好,所以我将代码放在$(this.find('.content').height((inHeight)+“px”)下面;现在我只需要知道曲线括号之间要写什么您只想应用于移动页面的代码。因此,可能是示例代码的第3-6行。但我仍然建议您仅使用CSS来响应。可能重复