Search code examples
javascripttouchdom-eventsflexslider

Wait To Get Touch Moves, Why?


I am working on a touch based JS application, I've studied Flex and Royal slider as examples. I noticed that both sliders acting similarly when getting touchmove event:

var started,touched ;
el.bind('touchstart',function(e){
    started = Number(new Date()) ;
    // Get pageX and pageY etc...
}) ;
el.bind('touchmove',function(e){
    touched = Number(new Date()) ;
    if (started-touched > 500) {
        // Handle touch moves etc...
    }
}) ;

My JS app works seamless without these, but why do they need to do this? Why they are waiting 500ms to get move datas?


Solution

  • I believe this is some kind of sensitivity setting. You only want to register a touch-move (drag) event if the user has been moving his or her finger across the device for at least 500ms (in this example).

    This could be useful to differentiate between taps and drags. Otherwise, if the user would slightly move his/her finger when clicking, for example, a button, the app would also register a drag. As some controls accept both events, this could lead to erroneous behaviour.