Reputation: 414
I have the following code:
$( window ).resize(function() {
if (matchMedia('only screen and (min-width: 992px)').matches) {
$('#second').parallax();
$('.sketches-1').parallax();
$('#fifth').parallaxfifth();
}
else{
//...
}
});
I wish to remove the parallax function on mobile devices, but how can I achieve this?
Upvotes: 0
Views: 290
Reputation: 25682
Use:
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);
If you don't want to use this effect on mobile simply use:
function isMobile() {
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
if (!isMobile()) {
$(window).resize(parallax);
}
Upvotes: 1