Javascript 如何阻止JS函数在移动设备上运行?
我正在运行以下代码,如果您正在使用移动设备,我需要使其停止Javascript 如何阻止JS函数在移动设备上运行?,javascript,jquery,function,Javascript,Jquery,Function,我正在运行以下代码,如果您正在使用移动设备,我需要使其停止 jQuery(document).ready(function($){ var inHeight = $("#wrapper").innerHeight(); $("#wrapper .col").each(function(){ $(this).height(inHeight+"px"); $(this).find('.content').height((inHeight-60)+"px
jQuery(document).ready(function($){
var inHeight = $("#wrapper").innerHeight();
$("#wrapper .col").each(function(){
$(this).height(inHeight+"px");
$(this).find('.content').height((inHeight-60)+"px");
});
});
我是否可以使用类似于if($(window).width()的方法尝试以下操作:
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() ) {....} else { // place your code here }
您可以尝试:
if(!(/iPhone|iPad|iPod|Android|webOS|BlackBerry|Opera Mini|IEMobile/i.test(navigator.userAgent) )) {
jQuery(document).ready(function($){
var inHeight = $("#wrapper").innerHeight();
$("#wrapper .col").each(function(){
$(this).height(inHeight+"px");
$(this).find('.content').height((inHeight-60)+"px");
});
});
}
因此,如果它不是移动设备,则运行代码
使用$(window.width
这不是一个很好的解决方案。想想如果我不使用移动设备,只需在我的浏览器窗口中更改尺寸,会发生什么情况您的解决方案看起来会起作用-您尝试过吗?只需将其反转(.width()>600
)并将您的代码放在其中。不不不。不要使用窗口宽度来确定它是否是移动设备!这个问题可能会帮助您使用窗口宽度来实现这一点,这将特别困难,因为非移动浏览器的大小也可以调整为这些宽度。发生这种情况时,您必须撤消所做的操作脚本完成了,然后在重新调整大小后重做,等等。只需检查useragent。或者更好的是,不要围绕等高列进行设计,除非您给它们一个静态高度。