double-touch gesture

by mmansion

HTML

<div id="test">tap me</div>

CSS

#test {width:200px;height:200px;text-align:center;line-height:200px;font-size:25px;background:#CCC}

JavaScript

function single_tap(){
    $("#test").html("single tap")
}

function double_tap(){
    $("#test").html("double tap")
}

var tapped=false
$("#test").on("touchstart",function(e){
    if(!tapped){
      tapped=setTimeout(function(){
          single_tap()
          tapped=null
      },300); //wait 300ms
    } else {
      clearTimeout(tapped);
      tapped=null
      double_tap()
    }
    e.preventDefault()
});