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:
Doesn't trigger when scrolling:
- click
- mouseup
Does trigger when scrolling:
- mousedown
- touchstart
- touchend
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?
if you want to do this for multiple elements and also need mouse and pointer events:
I did this with a bit of a different work around. It's definitely not very elegant and certainly not suited to most situations, but it worked for me.
I have been using jQuery's toggleSlide() to open and close input divs, firing the slide on touchstart. The problem was that when the user wanted to scroll, the touched div would open up. To stop this from happening, (or to reverse it before the user noticed) I added a touchslide event to the document which would close the last touched div.
In more depth, here is a code snippet:
The global variable stores the last touched div, and if the user swipes, the document.touchmove event hides that div. Sometimes you get a flicker of a div poking out but it works for what I need it to, and is simple enough for me to come up with.
Quoting from DA.:
This is a working example:
I've implemented an easier solution by doing this:
Some of these solutions worked for me, but in the end I found that this lightweight library was simpler to setup.
Tocca.js: https://github.com/GianlucaGuarini/Tocca.js
It's quite flexible and detects touch as well as swipe, double-tap etc.
I had the same problem, here's a quick solution which works for me
basically instead of handling touchstart immediately, wait for some milliseconds (200ms in this example), then check the scroll position, had scrollposition changed, then we need not to handle touchstart.