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
});
解决此问题的任何好方法?
答案 0 :(得分:1)
我找到了两个解决方案:
将.noSwipe
类添加到您想要选择的内容中。 (在我的情况下,这是不可能的)
首先检测移动设备和平板电脑设备,然后激活此插件,以便我这样做:
// 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 :(得分: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
});
});