How does jQuery implement Touch events
This article mainly shows you "jQuery how to achieve touch events", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "jQuery how to achieve touch events" this article.
Touch event
/ / Define some variablesvar ball = $('') .appendTo ('body'), startPosition = {}, elementPosition = {}; / / Listen for mouse and touch eventsball.on (' mousedown touchstart',function (e) {e.preventDefault (); / / Normalizing the touch event object e = (e.originalEvent.touches)? E.originalEvent.touches [0]: e; / / Recording current positions startPosition = {x: e.pageX, y: e.pageY}; elementPosition = {x: ball.offset () .left, y: ball.offset () .top}; / / These event listeners will be removed later ball.on ('mousemove.rem touchmove.rem',function (e) {e = (e.originalEvent.touches)? E.originalEvent.touches [0]: e; ball.css ({top:elementPosition.y + (e.pageY-startPosition.y), left: elementPosition.x + (e.pageX-startPosition.x),});}); ball.on ('mouseup touchend',function () {/ / Removing the heavy * move listeners ball.off (' .rem');}) The above is all the content of this article "how to achieve Touch event in jQuery". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!