


Overview of click events and commonly used events in js (PC and mobile)
1. Click event:
It is a click event on the PC side, but it is a click event on the mobile side. In mobile projects, we often distinguish clicks. What to do and what to do when double-clicking, so when the mobile browser recognizes the click, it will only execute it after confirming that it is a click. There will be a 300ms delay when using click on the mobile side: the browser will wait for the first click after the first click. , you still need to wait 300ms to see if the second click is triggered. If the second click is triggered, it does not belong to the click. If the second click is not triggered, it belongs to the click. However, in some scenarios, it is necessary
Cancel delay:(1) Still zoom: To use this method, you must completely disable zoom to achieve the goal. Although most mobile terminals can solve this delay problem, some Apple phones still cannot; width - the width of the viewport; height - the height of the viewport; initial-scale - the initial scaling ratio; minimum-scale - the minimum ratio that the user is allowed to zoom to; maximum-scale - the maximum ratio that the user is allowed to zoom to; user-scalable - the user Is it possible to manually zoom
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
(2) fastclick.js: FastClick is a lightweight library developed by FT Labs specifically to solve the 300 millisecond click delay problem of mobile browsers. In short, when FastClick detects the touchend event, it will immediately trigger a simulated click event through the DOM custom event, and block the click event that the browser actually triggers after 300 milliseconds
First Step: Introduce the fastclick.js file into the page.
Step 2: Add the following code to the js file: After the window load event, call FastClick.attach() on the body.window.addEventListener(function(){ FastClick.attach( document.body ); },false );
If your project uses JQuery, rewrite the above code as:
$(function() { FastClick.attach(document.body); });
(1) Use touchstart: touch events include touchstart, touchend, touchmove, etc. Simply use touchstart to replace click. But the problem is, what if I want to bind a click event and a sliding event to the same object? At this time, conflicts will occur. ;On the mobile side, when your finger clicks on an element, it will go through: touchstart --> touchmove -> touchend -->click
Touch event model:
Function | |
---|---|
Press your finger on the screen | |
Finger sliding on the screen | |
Finger off the screen | |
Triggered when closing/exiting under special circumstances |
|
Function | |
---|---|
Event type | |
Event source | |
Block default behavior | |
Stop propagation of events | |
x value of touch position | |
Current value and leaving value |
Event name | Function |
---|---|
click | Triggered when the mouse clicks |
mouseover | Triggered when the mouse pointer moves over the element |
mouseout | Triggered when the mouse pointer moves out of the element |
mouseenter | Triggered when the mouse pointer moves over the element (bubbles are not supported) |
mouseleave | Triggered when the mouse pointer moves out of the element (bubbling is not supported) |
mousemove | Triggered when the mouse pointer moves over the element |
mousedown | Fired when the mouse button is pressed on the element |
mouseup | Fired when the mouse button is released on the element |
mousewheel | Script that runs when the mouse wheel is being scrolled |
keydown | Triggered when the user presses a key |
keyup | Triggered when the user releases the key |
load | Triggered after the page has finished loading |
scroll | Script that runs when the element scroll bar is scrolled |
blur | Script that runs when the element loses focus |
focus | Script that runs when an element gets focus |
change | Script that runs when the element value is changed |
Commonly used events on mobile terminals:
Event name | Function |
---|---|
click | Fires when clicked (click) |
load | Triggered after the page has finished loading |
scroll | Script that runs when the element scroll bar is scrolled |
blur | Script that runs when the element loses focus |
focus | Script that runs when an element gets focus |
change | Script that runs when the element value is changed |
input | Replace keyup, keydown |
touch event model | Handling single-finger operations |
gesture event model | Handling multi-finger operations |
Use native JS to encapsulate Tap events to solve the 300ms delay on the mobile terminal
The above is the detailed content of Overview of click events and commonly used events in js (PC and mobile). 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

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
