2015-01-26 62 views
1

TouchSwipe是用於向您的網站添加滑動的好插件。但是,當這個插件被激活時,我有一個關於選擇文本的問題。無法在TouchSwipe jQuery插件中選擇文本

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

任何解決此問題的好方法?

回答

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?

我希望這也能幫助他人。

1

您最好附加滑動觸摸事件,所以它也可以在帶觸摸屏的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 
    }); 
});