我有以下代码:
$( window ).resize(function() {
if (matchMedia('only screen and (min-width: 992px)').matches) {
$('#second').parallax();
$('.sketches-1').parallax();
$('#fifth').parallaxfifth();
}
else{
//...
}
});
我想删除移动设备上的视差功能,但我该如何实现呢?
答案 0 :(得分:1)
使用:
var parallax = function() {
if (matchMedia('only screen and (min-width: 992px)').matches) {
$('#second').parallax();
$('.sketches-1').parallax();
$('#fifth').parallaxfifth();
}
else{
//...
}
};
$(window).resize(parallax);
//Some code here...
$(window).off('resize', parallax);
如果您不想在移动设备上使用此效果,请使用:
function isMobile() {
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
if (!isMobile()) {
$(window).resize(parallax);
}