[英]disable jquery/js on mobile
如何在移动设备上禁用以下代码(<768px)?
jQuery(document).ready(function() {
jQuery('.fullpage-wrapper').tilt({
maxTilt: 12,
perspective: 2500, // Transform perspective, the lower the more extreme the tilt gets.
easing: "cubic-bezier(.03,.98,.52,.99)", // Easing on enter/exit.
scale: 1.1, // 2 = 200%, 1.5 = 150%, etc..
speed: 2000, // Speed of the enter/exit transition.
transition: false, // Set a transition on enter/exit.
reset: false, // If the tilt effect has to be reset on exit.
glare: true, // Enables glare effect
maxGlare: 0.1 // From 0 - 1.
});
});
签出 window.matchMedia可用于检查给定媒体查询字符串是否与当前视口匹配。
在你的情况下,我会
if (window.matchMedia('(max-width: 768px)')) {
// Code to be executed if the viewport size is below 768px
}
通过 javascript 读取屏幕尺寸。
var w = window.innerWidth; // 总是返回像素 var h = window.innerHeight; // 总是返回像素
然后将 function call jQuery('.fullpage-wrapper').tilt 放入 if 语句中
if (w >= 768){ jQuery('.fullpage-wrapper').tilt({.... etc }
注意:检查哪种获取尺寸的方法适用于您的目标设备。 也许这可以更好地工作:
var ratio = window.devicePixelRatio || 1;
var w = screen.width * ratio;
var h = screen.height * ratio;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.