使用恒星禁用移动设备上的视差

时间:2013-11-25 16:14:37

标签: mobile parallax

我有一个问题,

我想在移动设备上禁用我的网站上的视差效果,所以我在不同的论坛上查看,我找到了这段代码:

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());
    }
};

jQuery(document).ready(function(){
if( !isMobile.any()){
    $(window).stellar();
    }
});

但这没用,有没有办法用一个简单的代码禁用stellar?

(我找到另一个检测设备的代码)

if(jQuery.browser.mobile)
{
console.log('You are using a mobile device!');
}
else
{
console.log('You are not using a mobile device!');
}

这个有效(使用.js)。

但我仍然不知道如何禁用恒星。

谢谢你们

2 个答案:

答案 0 :(得分:1)

按照您的第一个示例更改最后一部分:

if( !isMobile.any() )
$(function(){
    $.stellar({
    horizontalScrolling: false,
    verticalOffset: 50
    });
});

对我而言,它运作良好,声明说:“如果不是移动,那么初始化Stellar”。

请注意,您提供的移动代理列表不完整,适用于大多数设备,但请记住这一点!

答案 1 :(得分:0)

这段代码对我有用;

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());
    }
};



jQuery(document).ready(function(){
	

      jQuery(window).stellar({ 
	  horizontalScrolling: false,
	  hideDistantElements: true,
	  verticalScrolling: !isMobile.any(),
	  scrollProperty: 'scroll',
          responsive: true
	  });
	  
});

相关问题