A developper-friendly javascript touch library
CanTouchThis.js ⇒Presentation :
Since 1990, we all want to be able to "touch this" as will. But, it can be tricky to make it real on your favorite browser. Here come canTouchThis.js, a really simple javascript library that let you handle touch events as any other event.
New events :
We all know and love javascript events, so canTouchThis.js keep the same spirit. Some new events are just triggered when needed without interfering with the old ones.
Available events :- grab : a touch occurs on the element
- drag : the element is moved around
- drop : the touch end
- swipe : the element is quickly drag to a direction
- dbltap : a double-tap occurs on the element
- taphold : a long pressed touch occurs on the element
- pinch : two moving touch in a same element
Examples :
The code below is an example of how to detect swipe event.
element.addEventListener("swipe", function(ev){
if(ev.detail.direction == Touch.LEFT){
showPrevious();
}
else if(ev.detail.direction == Touch.RIGHT){
showNext();
}
};
Browser support :
The script use some new features supported only by most modern browser.