简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM