Méthode "tactile" jQuery autonome

Donc, je cherche à mettre en œuvre la possibilité d'un plugin que j'ai écrit pour lire un «glissement» tactile à partir d'un périphérique Internet tactile, comme un iPhone, un iPad ou un Android.

Y a-t-il quelque chose là-bas? Je ne cherche pas quelque chose aussi plein que jQtouch, mais envisage d'ingénierie inverse le code dont j'aurais besoin.

Des suggestions sur la meilleure façon d'aborder cela? Un extrait de code déjà disponible?

Addendum: je réalise en recul que la solution ne sera strictement pas jQuery, car je suis sûr qu'il n'y a pas de méthodes intégrées pour gérer cela. Je m'attends à ce que le Javascript standard se trouve dans la réponse.

(function($) { $.fn.swipe = function(options) { // Default thresholds & swipe functions var defaults = { threshold: { x: 30, y: 10 }, swipeLeft: function() { alert('swiped left') }, swipeRight: function() { alert('swiped right') }, preventDefaultEvents: true }; var options = $.extend(defaults, options); if (!this) return false; return this.each(function() { var me = $(this) // Private variables for each element var originalCoord = { x: 0, y: 0 } var finalCoord = { x: 0, y: 0 } // Screen touched, store the original coordinate function touchStart(event) { console.log('Starting swipe gesture...') originalCoord.x = event.targetTouches[0].pageX originalCoord.y = event.targetTouches[0].pageY } // Store coordinates as finger is swiping function touchMove(event) { if (defaults.preventDefaultEvents) event.preventDefault(); finalCoord.x = event.targetTouches[0].pageX // Updated X,Y coordinates finalCoord.y = event.targetTouches[0].pageY } // Done Swiping // Swipe should only be on X axis, ignore if swipe on Y axis // Calculate if the swipe was left or right function touchEnd(event) { console.log('Ending swipe gesture...') var changeY = originalCoord.y - finalCoord.y if(changeY < defaults.threshold.y && changeY > (defaults.threshold.y*-1)) { changeX = originalCoord.x - finalCoord.x if(changeX > defaults.threshold.x) { defaults.swipeLeft() } if(changeX < (defaults.threshold.x*-1)) { defaults.swipeRight() } } } // Swipe was canceled function touchCancel(event) { console.log('Canceling swipe gesture...') } // Add gestures to all swipable areas this.addEventListener("touchstart", touchStart, false); this.addEventListener("touchmove", touchMove, false); this.addEventListener("touchend", touchEnd, false); this.addEventListener("touchcancel", touchCancel, false); }); }; })(jQuery); $('.swipe').swipe({ swipeLeft: function() { $('#someDiv').fadeIn() }, swipeRight: function() { $('#someDiv').fadeOut() }, }) 

Et c'est ainsi que vous détectez l'iphone

 if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) { if (document.cookie.indexOf("iphone_redirect=false") == -1) window.location = "path to iphone page"; } 

La solution la plus petite et la plus jQuery-esque est ici: https://github.com/eikes/jquery.swipe-events.js