The actual reference to js's touch event

  • 2020-03-30 04:04:47
  • OfStack

At the beginning of the front-end page, I was exposed to js, but then I was attracted by the simple and efficient jquery, and I have been using it ever since.

Js, however, was abandoned by my subjective view of the underlying technology.

Since I know little about js, I have tried the simplest applications for a long time... Let's share the actual reference to js's touch event:


$(function(){
document.addEventListener("touchmove", _touch, false);
})

function _touch(event){
alert(1);
}

The above code inevitably USES something about jquery, which can be ignored if you don't use jquery.

The corresponding events are:

Touchstart: triggered when a finger touches the screen; Even if a finger is already on the screen, it will trigger.
Touchmove: continuous trigger when a finger is swiped across the screen. During this event, the preventDefault() call prevents scrolling.
Touchend: triggered when a finger is removed from the screen.
Touchcancel: triggered when the system stops tracking touches. The exact trigger event for this event is not specified in the documentation.

The event object of the above events has the following properties above:
Touches: an array of Touch objects representing the currently traced Touch operation.
TargetTouches: an array of Touch objects specific to the event target.
ChangeTouches: an array of Touch objects that indicate what has changed since the last Touch.

Each Touch object contains the following properties:
ClientX: touches the X coordinate of the target in the viewport.
ClientY: touches the target's Y coordinate in the viewport.
Identifier: represents the unique ID of the touch.
PageX: touches the x coordinates of the target in the page.
PageY: touches the target's y coordinate on the page.
ScreenX: touch the x coordinate of the target on the screen.
ScreenY: touch the target's y coordinate on the screen.
Target: touches the DOM node coordinates

Well, I actually just started to learn, anyway, some attributes of baidu to write down.


Related articles: