Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jQuery implement Touch events

Shulou Source: shulou.com Published: 2022-06-01 04:17:37 09月22日 Update

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!

Tags: Events content articles learning help easy to understand more organization knowledge editing industry information information channels channels research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Xiaomi NVidia macOS MariaDB