Mobile JavaScript
Device Events
Pointer Events
if (window.navigator.pointerEnabled) {
// Pointer events are supported.
canvas.addEventListener("pointermove", paint, false);
}
else {
canvas.addEventListener("mousemove", paint, false);
}
function paint(event) {
if (event.pointerType) {
switch (event.pointerType) {
case "touch":
// A touchscreen was used
break;
case "pen":
// A pen was used
break;
case "mouse":
// A mouse was used
break;
}
}
}
Touch Events
Testing
StackOverflow: Touchscreen media-queries
<script>
// iOS //
iOS_touch = typeof window.TouchEvent !== 'undefined' ? true : false;
iPad_touch = typeof window.Touch !== 'undefined' ? true : false;
// Mini Modernizr //
document.documentElement.className += ("ontouchstart" in document.documentElement) ? ' touch' : ' no-touch';
</script>
Touch Libs
- jQuery Plugins That Handle Touch Events – 43 Items
- toe.js
- tap
- taphold
- swipe: event.direction (up, right, down, left)
- transform: event.center (…pageX, …pageY) , event.scale, event.rotation
- Zepto.js
- tap
- singleTap and doubleTap
- longTap
- swipe, swipeLeft, swipeRight, swipeUp, swipeDown
- jQuery Mobile Events
- tapstart
- tapend
- tap
- singletap
- doubletap
- taphold
- swipe
- swipeup
- swiperight
- swipedown
- swipeleft
- swipeend
- scrollstart
- scrollend
- orientationchange
- TipTap - The TipTap library is a javascript library to ease mouse and touch complex gestures definition and management on HTML DOM elements, as well as to provide a unified way of managing different input devices systems: mouse, touch systems and their specific data structure (iOS, Android, Windows…), Leap Motion hopefully, etc.
- Hammer.js - At only 3kb when gzipped, it is a lightweight and efficient library.
- tap, doubletap, hold
- drag, dragstart, dragend, dragup, dragdown, dragleft, dragright
- swipe, swipeup, swipedown, swipeleft, swiperight
- transform, transformstart, transformend
- pinch, pinchin, pinchout
- rotate
- touch (gesture detection starts)
- release (gesture detection ends)
- Touchy.js is a simple light-weight (1.98 kb minified+gzip) JavaScript library for dealing with touch events in the browser. jQuery & Zepto plugin as well.
- jQuery Mobile
- jQuery.pep.js is a lightweight jQuery plugin which turns any DOM element into a draggable object.
- jquery-ui-for-ipad-and-iphone - Provides an interface layer to map touch events to jQuery UI interface elements.
- jQuery UI Touch Punch is a small hack that enables the use of touch events on sites using the jQuery UI user interface library.
- HotStudio: Touchy - GitHub - The minified file size is 9.43KB (2.69KB gzipped). jQuery Plugin.
- touchy-longpress
- touchy-drag
- touchy-pinch
- touchy-rotate
- touchy-swipe
- jGestures jQuery Plugins
- DoubleTap for jQuery
- touch (triggered for all events)
- swipe (triggered for all swipe events)
- tap (no horizontal or vertical movement)
- doubletap
- swipeleft
- swiperight
- swipeup
- swipedown
- WKTouch - A JavaScript plugin for touch-capable devices, enabling multi-touch drag, scale and rotate on HTML elements.
- iScroll 4
- Pinch / Zoom
- Pull up/down to refresh
- Improved speed and momentum
- Snap to element
- Customizable scrollbars
Simple Touch Events
- Tappable - GitHub - A simple, standalone library to invoke the tap event for touch-friendly web browsers.
- Swipe - GitHub - A is the most accurate touch slider.
- TouchSwipe - GitHub jQuery Plugin.
- Swipe: up, down, left, right
- Pinch: in, out
- Touch Events: Single and double finger
- Supports click events on touchSwipe object and its child objects
- Touch: start, move, end, cancel
- Definable threshhold / maxTimeThreshold
- End event on touch release or threshhold
- Allows swiping and page scrolling
- Disables user input elements (Button, form, text etc) from triggering swipes
- Jon Packer: jquery.tap is a tap listener for jquery. jQuery Plugin.
- Aaron Gloege: jQuery.tap - A jQuery plugin that creates a click alternative for touch enabled browsers. jQuery Plugin.
- Aaron Gloege: jquery.touchHooks - fixHooks for jQuery so touch events copy event data. jQuery Plugin.
Pollyfills & Utils
- thumbs.js - Add touch support to your browser.
- touchstart / mousedown
- touchmove / mousemove
- touchend / mouseup
- HandJS
- pointerdown
- pointermove
- pointerup
- pointercancel
- pointerenter
- pointerleave
- pointerout
- pointerover
- Touché - Mouse event to touch event mapping for testing touch interfaces with desktop browsers.
- mousedown > touchstart
- mousemove > touchmove
- mouseup > touchend
- Lightning Touch - WebApp interface (all pages in one page style Ala. WAP “deck”).