首页 > 解决方案 > jquery touchswipe 插件在 iOS 上无法正常工作

问题描述

所以基本上我正在开发一个网站,其中滚动事件的默认值被阻止,而是每次滚动都会带你向下或向上到下一个“部分”。这在 PC 和某些手机上非常有效,但在 iOS 上,滚动只是变得一团糟,坦率地说,我没有想法。

我正在使用的移动滚动 API 是 jquery touchSwipe https://github.com/mattbryson/TouchSwipe-Jquery-Plugin

下面的代码是应该完成所有工作的函数。

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
        $(window).swipe({
          swipe:function(event, direction, distance, duration, fingerCount, fingerData) {
            if (scrolling == false && direction === "down") {
              scrolling = true;
              scrollSection = Math.round($(window).scrollTop()/window.innerHeight);
              scrollTo_(event,sections[scrollSection-1]);
              setTimeout(function() {
                scrolling = false;
              }, 1000);
            }
            else if (scrolling == false && direction === "up") {
              scrolling = true;
              scrollSection = Math.round($(window).scrollTop()/window.innerHeight);
              scrollTo_(event,sections[scrollSection+1]);
              setTimeout(function() {
                scrolling = false;
              }, 1000);
            }
          }
        });
      }

如果您有任何问题,请告诉我,我会更新这个问题。

标签: javascriptjquery

解决方案


你试过这个吗?最近几天在我的网络应用程序中,我研究了 Jquery UI 滑块,这对手机不起作用,所以在附加它之后它就可以工作了。


推荐阅读