![](/img/trans.png)
[英]How to handle window resize for displaying canvas for mobile devices with devicepixelratio
[英]Exclude javascript window resize from mobile devices
是否可以從移動設備中排除/忽略該JavaScript?
function doSomething() {
location.reload();
};
var resizeTimer = null;
$(window).bind('resize', function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(doSomething, 100);
});
謝謝!
jQuery只是包裝標准的resize DOM事件,例如。
window.onresize = function(event) {
...
}
$(function(){
var mobile;
if (window.width < 481) {
mobile = 1;
}
if (!mobile) {
// All your stuff.
}
});
//Class for Detecting Mobile devices
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());
}
};
var resizeTimer = null;
//if not mobile do resize
if( !isMobile.any() ){
$(window).bind('resize', function() {
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(doSomething, 100);
});
};
function doSomething() {
location.reload();
};
供你參考
http://www.abeautifulsite.net/blog/2011/11/detecting-mobile-devices-with-javascript/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.