Since the Google code is very complicated, I implemented my own using Mootools 1.3 +:
Element.Events.touch = { base: 'touchend', condition: function(e) { return ((new Date().getTime() - this.startT < 200) && this.valid) ? true : false; }, onAdd: function(fn) { this.addEvent('touchstart', function(e) { this.valid = true; this.startT = new Date().getTime(); this.startX = e.touches[0].clientX; this.startY = e.touches[0].clientY; }); this.addEvent('touchmove', function(e) { if ((Math.abs(e.touches[0].clientX - this.startX) > 10) || (Math.abs(e.touches[0].clientY - this.startY) > 10)) this.valid = false; }); } };
Just put this code on your page and now use touch , not click :
$('id').addEvent('touch', function() { // your code });
It works by adding the touchhend and touchstart events if they happen in less than 200 ms, and a touch does not affect its actual touch too much, and not vice versa.
It worked great on 2.2 and 4.0
Ali
source share