簡體   English   中英

取消自定義功能與元素的綁定

[英]Unbind custom function from element

我有以下代碼:

    $( window ).resize(function() {
        if (matchMedia('only screen and (min-width: 992px)').matches) {
            $('#second').parallax();
            $('.sketches-1').parallax();
            $('#fifth').parallaxfifth();
        }
        else{
            //...
        }
   }); 

我希望刪除移動設備上的視差功能,但是如何實現呢?

采用:

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

如果您不想在移動設備上使用此效果,請使用:

function isMobile() {
  /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

if (!isMobile()) {
  $(window).resize(parallax); 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM