2016-11-27 71 views
0

我正在創建新的網站,並需要有關JavaScript的幫助。 我想要的是在手機上禁用scrollify JS。 嘗試幾乎一切,不成功。如何在手機上禁用scrollify.js

這裏是我的代碼:

<script> 
      $(function() { 
        $.scrollify({ 
         section : ".pagescroll", 
         standardScrollElements: ".modal", 
        }); 
       $.scrollify.disable() // this function is for disable mobile 
       }); 
</script> 

謝謝

+0

你怎麼想如果移動設備正在使用您的代碼來檢測? –

+0

例如檢測屏幕尺寸<600px – YakaMan

+0

看看[this](http://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window )SO問題 –

回答

0

你爲什麼不檢查它是否使用userAgentregex這樣

您可以執行你的script只有當它不就是移動手機

if(!(/Android|webOS|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i.test(navigator.userAgent))) { //if not these devices(userAgents) 

    $(function() { 
     $.scrollify({ 
      section : ".pagescroll", 
      standardScrollElements: ".modal", 
     }); 
    }); 

} 

您也可以在手機SO網站試試下面的代碼片段。它的工作

if(!(/Android|webOS|BlackBerry|iPhone|iPad|iPod|Opera Mini|IEMobile/i.test(navigator.userAgent))) { //if not these userAgents 
 
    console.log("Not Mobile..!"); 
 
}else{ 
 
    console.log("This is Mobile"); 
 
}

+0

看着userAgent並不是一個好主意;這是不可靠的,必須保持。 –

+0

需要幫助,因爲我是JavaScript函數的新手。 謝謝 – YakaMan

+0

@YakaMan #Soadyto幫助。很高興幫助你:) –

-1

檢查這個代碼...

<script> 
$(document).ready(function() { 
    var width = $(window).width(); 
    var height = $(window).height(); 

    if (width > 980 && height > 500) { 
     $(function() { 
      $(".panel").css({ 
       "height": $(window).height() 
      }); 
      $.scrollify({ 
       section: ".panel" 
      }); 


      $(".scroll").click(function (e) { 
       e.preventDefault(); 
       $.scrollify("move", $(this).attr("href")); 
      }); 
     }); 

    } else { 
     $(".scroll").click(function (e) { 
      e.preventDefault(); 
     }); 
     $.scrollify.destroy(); 
    } 
    $(window).resize(function() { 
     width = $(window).width(); 
     height = $(window).height(); 
     $(function() { 
      if (width > 980 && height > 500) { 
       $(".panel").css({ 
        "height": $(window).height() 
       }); 
       $.scrollify({ 
        section: ".panel" 
       }); 


       $(".scroll").click(function (e) { 
        e.preventDefault(); 
        $.scrollify("move", $(this).attr("href")); 
       }); 
      } else { 
       $.scrollify.destroy(); 
       $(".scroll").click(function (e) { 
        e.preventDefault(); 
       }); 

      } 
     }); 
    }); 
}); 

+0

歡迎來到SO。發佈答案時,請附上評論,說明問題的原因以及您的代碼如何解決問題。 – Fejs