【问题标题】:Can't select text in TouchSwipe jQuery plugin无法在 TouchSwipe jQuery 插件中选择文本
【发布时间】:2015-01-26 19:39:19
【问题描述】:

TouchSwipe 是一个很棒的插件,可以将滑动添加到您的网站。但是当这个插件被激活时,我在选择文本时遇到了问题。

     $(window).swipe( {
        //Generic swipe handler for all directions
        swipeRight:function(event, direction, distance, duration, fingerCount) {
                dnlShow();
        },
        swipeLeft:function(event, direction, distance, duration, fingerCount) {
                dnlHide();
        },
        //Default is 75px, set to 0 for demo so any distance triggers swipe
        threshold: 75
      });

有什么好的办法可以解决这个问题吗?

【问题讨论】:

    标签: javascript jquery mobile touch swipe


    【解决方案1】:

    我找到了两个解决方案:

    1. .noSwipe 类添加到您希望可选择的内容。 (在我的情况下这是不可能的)

    2. 先检测手机和平板设备,然后激活这个插件,所以我这样做了:

      // Check if you are in mobile or not
      // Code credit: https://stackoverflow.com/questions/3514784/what-is-the-best-way-to-detect-a-mobile-device-in-jquery
      function isMobile() {
        try{ document.createEvent("TouchEvent"); return true; }
        catch(e){ return false; }
      }
      
      if ( isMobile() == true ) {
          // Swipe plugin for handling touch events
          $(window).swipe( {
          //Generic swipe handler for all directions
          swipeRight:function(event, direction, distance, duration, fingerCount) {
                  dnlShow();
          },
          swipeLeft:function(event, direction, distance, duration, fingerCount) {
                  dnlHide();
          },
          //Default is 75px, set to 0 for demo so any distance triggers swipe
          threshold: 75
        });
      }
      

    检测手机和平板设备有多种解决方案,您可以查看What is the best way to detect a mobile device in jQuery?

    我希望这对其他人也有帮助。

    【讨论】:

      【解决方案2】:

      您最好将滑动附加到触摸事件,因此它也适用于带有触摸屏的 PC。 代码如下:

      $(document).on("touchstart", function(event) {
          $(window).swipe( {
              swipeRight:function(event, direction, distance, duration, fingerCount) {
                      dnlShow();
              },
              swipeLeft:function(event, direction, distance, duration, fingerCount) {
                      dnlHide();
              },
              threshold: 75
          });
      });
      

      【讨论】:

        猜你喜欢
        • 2012-04-05
        • 2010-12-06
        • 1970-01-01
        • 2016-12-01
        • 2011-11-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多