如何在移动设备上禁用scrollify.js

时间:2016-11-27 12:39:23

标签: javascript scroll

我正在创建新的网络,需要JavaScript帮助。 我想要的是在移动设备上禁用scrollify JS。 几乎尝试了一切,而不是成功。

这是我的代码:

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

谢谢

4 个答案:

答案 0 :(得分:1)

为什么不使用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网站上试用以下代码段。它的工作

&#13;
&#13;
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");
}
&#13;
&#13;
&#13;

答案 1 :(得分:1)

jQuery.scrollify({
    touchScroll: false
});

touchScroll:一个布尔值,用于定义Scrollify是否处理触摸滚动事件。默认为True。

答案 2 :(得分:0)

检查此代码......

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

            }
        });
    });
});

答案 3 :(得分:0)

$.scrollify({
 section : ".fullSec",
 scrollSpeed:2000,
 easing: "easeOutExpo",
 offset : 0,
 scrollbars: true,
 setHeights: true,
 updateHash: false,
 afterResize: function() {
 if( $(window).width() < 767) {
   $.scrollify.disable()
 }else{
   $.scrollify.enable()
 }
 },
});