Reputation: 1
HI friends I have to disable script for parallax effects when open on mobile phones. I found a script similar to what I wanted and adapted, however it does not work. Anyone know what's wrong?
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(): false;
}
});
Upvotes: 0
Views: 3151
Reputation: 40639
Try this,
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);
}
};
var any=(isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
jQuery(document).ready(function(){
if(!any){
alert('No mobiles');
$(window).stellar();
}
});
Upvotes: -1
Reputation: 207501
Open up the console in your browser.
Go to this fiddle: http://jsfiddle.net/vyPjx/
You will see the error
Uncaught SyntaxError: Unexpected token :
The error will point to the line
$(window).stellar(): false;
Looks like you were trying to use a ternary operator but you are not?
It should be just
$(window).stellar();
If you were going the ternary route it would have been
jQuery(document).ready(function(){
var hasRun = !isMobile.any() ? $(window).stellar() : false;
});
Upvotes: 0
Reputation: 20159
jQuery(document).ready(function(){
if( !isMobile.any()){
$(window).stellar(): false;
}
});
That third line is syntactically wrong. What exactly are you trying to achieve with something likefn(): false;
?
I believe you're looking for:
jQuery(document).ready(function(){
if( !isMobile.any() ){
$(window).stellar();
}
});
In other words: only if !isMobile.any()
should $(window).stellar()
be executed. In the other case (where isMobile.any()
is true
), the if
block should not be executed.
Upvotes: 1
Reputation: 150010
What is the : false
after $(window).stellar()
? I'm not sure what you're trying to do there, or if it's just some kind of copy/paste error or something, but that will give:
SyntaxError: Unexpected token :
I think you want this:
jQuery(document).ready(function(){
if( !isMobile.any()){
$(window).stellar();
}
});
Upvotes: 2