Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<script>
function NoClickDelay(el) {
  this.element = el;
  if( window.Touch ) this.element.addEventListener('touchstart', this, false);
}
  
NoClickDelay.prototype = {
  handleEvent: function(e) {
    switch(e.type) {
      case 'touchstart': this.onTouchStart(e); break;
      case 'touchmove': this.onTouchMove(e); break;
      case 'touchend': this.onTouchEnd(e); break;8
    }
  },
  onTouchStart: function(e) {
    e.preventDefault();
    this.moved = false;
    this.element.addEventListener('touchmove', this, false);
    this.element.addEventListener('touchend', this, false);
  },
  onTouchMove: function(e) {
    this.moved = true;
  },
  onTouchEnd: function(e) {
    this.element.removeEventListener('touchmove', this, false);
    this.element.removeEventListener('touchend', this, false);
    if( !this.moved ) {
      var theTarget = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
      if(theTarget.nodeType == 3) theTarget = theTarget.parentNode;
      var theEvent = document.createEvent('MouseEvents');
      theEvent.initEvent('click', true, true);
      theTarget.dispatchEvent(theEvent);
    }
  }
};
$(document).ready(function() {
  $('.noclickdelay').each(function(i,node) {
    alert(1);
    new NoClickDelay(node);
  });
  var startTime;
  $('button')
    .bind('touchstart', function(e) { startTime = e.timeStamp; })
    .click(function(e) { $('#result').html(e.timeStamp - startTime); });
});
</script>
</head>
<body>
  <button id="slowBtn">Slow Button</button>
  <button id="fastBtn" class="noclickdelay">Fast Button</button>
  <div id="result"></div>
</body>
</html>
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers