Mandi
Mandi

Reputation: 414

Unbind custom function from element

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

Answers (1)

Minko Gechev
Minko Gechev

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

Related Questions