Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use HTML touch event on Mobile

Shulou Source: shulou.com Published: 2022-05-31 12:33:41 09月28日 Update

This article mainly introduces how to use HTML touch event in mobile terminal, the content is detailed and easy to understand, the operation is simple and fast, and it has certain reference value. I believe everyone will gain something after reading this article on how to use HTML touch event in mobile terminal. Let's take a look at it together.

1.touchstart

Trigger when finger touches screen

dom.addEventListener('touchstart',function(e){});startX=e.touches[0].clientX;

The e object returned by the event contains mobile-specific attributes:

tarchTouches: all current touches of the target element

changedTouches: all recently changed touches on the page

touches: all touches on the page

2.touchmove

Triggers continuously as your finger slides across the screen

dom.addEventListener('touchmove',function(e){});

The e object returned by the event contains mobile-specific attributes:

tarchTouches: all current touches of the target element

changedTouches: all recently changed touches on the page

touches: all touches on the page

3.touchend

Trigger when finger leaves screen

dom.addEventListener ('touchend ',funciton(e){});//Touches can't get touch object in touchend,//because touch has ended, changedTouches gets touch object//console.log (e);//endX=e.touches[0]; undefined endX=e.changedTouches [0].clientX;

The e object returned by the event contains mobile-specific attributes:

changedTouches: all recently changed touches on the page

touchcancel: Triggered when the system stops tracking touches. (Not often used)

event notification records changeTouches at the time of the touchend event

4. e.touches[0]

clientX: Touch the X coordinate of the target in the viewport.

clientY: Touch the Y coordinate of the target in the viewport.

pageX: X coordinate of the touch target in the page.

pageY: y coordinate of the touch target in the page.

screenX: Touch the x coordinate of the target on the screen.

screenY: Touch the y coordinate of the target on the screen.

The content of this article on "How to use HTML touch events in mobile" is introduced here. Thank you for reading! I believe everyone has a certain understanding of the knowledge of "how to use HTML touch events in mobile terminal." If you still want to learn more knowledge, please pay attention to the industry information channel.

Tags: Events targets moves pages coordinates objects screens attributes fingers knowledge elements content time articles viewports values commonly used easy to operate articles easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker macOS OPPO Reno Redmi