function gi(id){ return document.getElementById(id); } function gn(name){ return document.getElementsByName(name); } function gt(tag, el){ return (el || document).getElementsByTagName(tag); } function attr(el, at, value){ at = {'for': 'htmlFor', 'class': 'className'}[at] || at; if(!value){ return el[at] || el.getAttribute(at) || ''; }else{ el[at] = value; if (el.setAttribute) el.setAttribute(at, value); } } function GetElByClass(name, type) { var r = []; var re = new RegExp("(^|\\s)" + name + "(\\s|$)"); var e = (type) ? gt(type) : ((navigator.userAgent.indexOf("MSIE") >= 0) ? document.all : gt("*")); for ( var j = 0; j < e.length; j++ ){ if (re.test(attr(e[j], "class"))){ r.push( e[j] ) } } return r; } function Touch($class){ var ids = []; ids = GetElByClass($class,'div'); var touchstartX = 0 ,touchstartY = 0, touchendX = 0, touchendY = 0; for (var i = 0; i < ids.length; i++) { (function(i) { ids[i].addEventListener('touchstart', function(e){ touchstartX = event.changedTouches[0].screenX; touchstartY = event.changedTouches[0].screenX; }, false) ids[i].addEventListener('touchend', function(e){ touchendX = event.changedTouches[0].screenX; touchendY = event.changedTouches[0].screenX; handleGesure(); }, false) }) (i); } function handleGesure() { var swiped = 'swiped: '; if (touchendX < touchstartX) { console.log(swiped + 'left!'); } if (touchendX > touchstartX) { console.log(swiped + 'right!'); } if (touchendY == touchstartY) { console.log('tap!'); } } }