滑动时防止touchstart [英] prevent touchstart when swiping
问题描述
我在移动设备上有可滚动的列表。他们希望人们能够通过滑动滚动列表,并通过点击选择一行。
I have a scrollable list on a mobile device. They want people to be able to scroll the list via swiping, and also select a row by tapping.
这两个问题正在结合。如果您实际滚动列表,我不希望选择一行。这是我发现的:
The catch is combining the two. I don't want a row to be selected if you are actually scrolling the list. Here's what I've found:
滚动时不触发:
- 单击
- mouseup
滚动时是否触发:
- mousedown
- touchstart
- touchend
简单的解决方案是坚持点击事件。但我们发现,在某些黑莓设备上,touchstart之间存在非常明显的延迟,然后触发点击或鼠标。这种延迟足以使它在这些设备上无法使用。
The simple solution is to just stick with the click event. But what we're finding is that on certain blackberry devices, there is a VERY noticeable lag between touchstart and it then triggering either click or mouseup. This delay is significant enough to make it unusable on those devices.
因此,我们留下了其他选项。但是,使用这些选项,您可以滚动列表而不触发您触摸的行以开始滚动。
So that leaves us with the other options. However, with those options, you can scroll the list without triggering the row you touched to start the scroll.
此处解决此问题的最佳做法是什么?
What is the best practice here to resolve this?
推荐答案
var touchmoved;
$('button').on('touchend', function(e){
if(touchmoved != true){
// button click action
}
}).on('touchmove', function(e){
touchmoved = true;
}).on('touchstart', function(){
touchmoved = false;
});
这篇关于滑动时防止touchstart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!