


Detailed explanation of the use of click, touch, and tap events in mobile WEB development
This time I will bring you a detailed explanation of the use of click, touch, and tap events in mobile WEB development, and precautions for the use of click, touch, and tap events in mobile WEB development. What are they? The following is a practical case. Let’s take a look.
1. Comparison between click and tap
Both will be triggered when clicked, but on the mobile WEB side, click will have 200~300 ms, so please use tap instead of click as the click event.
singleTap and doubleTap Represents single click and double click respectively.
2. Regarding the click-through processing of tap
When using the tap of the zepto framework to move the click event in the device browser, to avoid When the click event is delayed in response, there may be a click-through situation, that is, the click will trigger a click event on a non-current layer.
Processing method:
(1),
There is a library called fastclick on github, which can also avoid delayed response to click events on mobile devices, https:// github.com/ftlabs/fastclick
Introduce it into the page with a script tag (the library supports AMD, so you can also use AMD specifications such as require.js module loader introduction), and initialize it on the body when the dom is ready, such as:
$(function(){ newFastClick(document.body); })
Then bind the click event to the element that requires "no delay click" (Note that it is no longer the tap event bound to zepto).
Of course, you can also initialize it not on the body, but on a certain dom. In this way, only this dom and its sub-elements can enjoy "delay-free" clicks
In practical development, it was found that when the element is bound to fastclick, the click response speed is slightly faster than tap. Haha
(2) Bind the touchend event to the element and add e.preventDefault();
$demo.on('touchend',function(e){//改变了事件名称,tap是在body上才被触发,而touchend是原生的事件,在dom本身上就会被捕获触发 $demo.hide() e.preventDefault();//阻止“默认行为” })
<span style='font-family: 微软雅黑, "Microsoft YaHei"; font-size: 14px;'></span>
3. Touch event touch is for touch events on touch screen mobile phones. Most touch screen mobile phone webkit kernels today provide touch event monitoring, allowing developers to obtain some information when the user touches the screen.
Including: touchstart, touchmove, touchend, touchcancel These four events
touchstart, touchmove, and touchend events can be compared to the triggering of mousedown, mouseover
, and mouseup.
touchstart: Triggered when the finger touches the screen;
touchmove: Triggered when the finger moves on the screen;
touchend: It will be triggered when the finger leaves the screen;
And touchcancel, many people don’t know when it will be triggered and ignore it. In fact, When your finger has not left the screen, touchcancel will be triggered when a system-level operation occurs, such as alert and confirm pop-ups, or android system function pop-ups.
The triggering order of these four events is:
touchstart
-> touchmove
-> …… -> touchmove ->touchend
But just monitoring the above single event is not enough for us to complete the monitoring of some gestures operations that are common on touch screen phones, such as double-click, long press, left and right sliding, zooming and other gestures. operate. It is necessary to combine monitoring of these events to encapsulate this type of gesture action.
In fact, many frameworks on the market have encapsulated these gestures for mobile browsers, such as jqmobile, zepto, and jqtouch. However, tragedy happened. For some android systems (I tested it myself In android 4.0.x), touchmove and touchend events cannot be triggered well. Here is an example:
For example, when a finger drags the page from top to bottom on the screen, theoretically Yes will trigger a touchstart
, many times touchmove
, and the final touchend, but on Android 4.0, touchmove is only triggered once, the triggering time is about the same as touchstart
, and touchend is not triggered directly. This is a very serious bug. Many people have raised it in google Issue http://code.google.com/p/android/issues/detail?id=19827
## For the time being, I only found that this bug exists in Android 4.0, and it is said that the iOS 3.x version will also have it.
Obviously jqmobile, zepto, etc. are not aware of the serious impact of this bug on the monitoring implementation, so when directly using the events of these frameworks, there will be more or less compatibility. Sex problem!
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! <span style='font-family: 微软雅黑, "Microsoft YaHei"; font-size: 14px;'></span>
Recommended reading:<span style='font-family: 微软雅黑, "Microsoft YaHei"; font-size: 14px;'></span>
The above is the detailed content of Detailed explanation of the use of click, touch, and tap events in mobile WEB development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Introduction to Caddy Caddy is a powerful and highly scalable web server that currently has 38K+ stars on Github. Caddy is written in Go language and can be used for static resource hosting and reverse proxy. Caddy has the following main features: Compared with the complex configuration of Nginx, its original Caddyfile configuration is very simple; it can dynamically modify the configuration through the AdminAPI it provides; it supports automated HTTPS configuration by default, and can automatically apply for HTTPS certificates and configure it; it can be expanded to data Tens of thousands of sites; can be executed anywhere with no additional dependencies; written in Go language, memory safety is more guaranteed. First of all, we install it directly in CentO

Form validation is a very important link in web application development. It can check the validity of the data before submitting the form data to avoid security vulnerabilities and data errors in the application. Form validation for web applications can be easily implemented using Golang. This article will introduce how to use Golang to implement form validation for web applications. 1. Basic elements of form validation Before introducing how to implement form validation, we need to know what the basic elements of form validation are. Form elements: form elements are

Using Jetty7 for Web Server Processing in JavaAPI Development With the development of the Internet, the Web server has become the core part of application development and is also the focus of many enterprises. In order to meet the growing business needs, many developers choose to use Jetty for web server development, and its flexibility and scalability are widely recognized. This article will introduce how to use Jetty7 in JavaAPI development for We

Face-blocking barrage means that a large number of barrages float by without blocking the person in the video, making it look like they are floating from behind the person. Machine learning has been popular for several years, but many people don’t know that these capabilities can also be run in browsers. This article introduces the practical optimization process in video barrages. At the end of the article, it lists some applicable scenarios for this solution, hoping to open it up. Some ideas. mediapipeDemo (https://google.github.io/mediapipe/) demonstrates the mainstream implementation principle of face-blocking barrage on-demand up upload. The server background calculation extracts the portrait area in the video screen, and converts it into svg storage while the client plays the video. Download svg from the server and combine it with barrage, portrait

First of all, you will have a doubt, what is frp? Simply put, frp is an intranet penetration tool. After configuring the client, you can access the intranet through the server. Now my server has used nginx as the website, and there is only one port 80. So what should I do if the FRP server also wants to use port 80? After querying, this can be achieved by using nginx's reverse proxy. To add: frps is the server, frpc is the client. Step 1: Modify the nginx.conf configuration file in the server and add the following parameters to http{} in nginx.conf, server{listen80

Web standards are a set of specifications and guidelines developed by W3C and other related organizations. It includes standardization of HTML, CSS, JavaScript, DOM, Web accessibility and performance optimization. By following these standards, the compatibility of pages can be improved. , accessibility, maintainability and performance. The goal of web standards is to enable web content to be displayed and interacted consistently on different platforms, browsers and devices, providing better user experience and development efficiency.

Cockpit is a web-based graphical interface for Linux servers. It is mainly intended to make managing Linux servers easier for new/expert users. In this article, we will discuss Cockpit access modes and how to switch administrative access to Cockpit from CockpitWebUI. Content Topics: Cockpit Entry Modes Finding the Current Cockpit Access Mode Enable Administrative Access for Cockpit from CockpitWebUI Disabling Administrative Access for Cockpit from CockpitWebUI Conclusion Cockpit Entry Modes The cockpit has two access modes: Restricted Access: This is the default for the cockpit access mode. In this access mode you cannot access the web user from the cockpit

nginx can not only hide version information, but also supports custom web server information. Let’s take a look at the final hidden result. How to achieve it? It’s actually very simple. Please look down 1. Official website to download the latest stable version wgethttp://nginx.org/ download/nginx-1.14.1.tar.gz2 Unzip tar-xfnginx-1.14.1.tar.gzcdnginx-1.14.13 Modify the c file (1) vimsrc/http/ngx_http_header_filter_module.c #Modify line 49 staticu_charngx_http_
