js implementation of Mac touchpad two-finger event summary
Preface
When fixing a web problem these days, I need to capture the Mac touchpad two-finger events (up, down, left, right, zoom in, zoom out), but I found that there is no ready-made wheel, so I still have to make it myself. .
For example: jquery.mousewheel.js (add cross-browser mouse wheel support), it is too simple and does not handle the Mac two-finger behavior, so it cannot be used.
Target
There are two specific ways to obtain the Mac touchpad two-finger behavior, one is real-time dragging route, and the other is gesture (up, down, left, right, zoom in, zoom out).
Difficulty
The two-finger action will only trigger the mousewheel event. Other touches and mouse events will not be triggered. You can only start with this.
Two-finger feature
1. During the rapid sliding process, the positive and negative values of the initial values of deltaX and deltaY are different from the sliding direction.
2. During the slow sliding process, the range of deltaX and deltaY values is very small, generally in [-3, 3].
3. Within 1 second, the mousewheel event is triggered about 100 times.
4. During the sliding process, the numerical value will have jitter problem.
Implement drag route idea (Path)
For quick swipes
1. The data whose initial positive and negative values of deltaX and deltaY are different from the sliding direction must be discarded. (Because it is not the real direction)
2. The deltaX and deltaY values of each trigger are subtracted from each other. If the result value is different from the direction, it is discarded.
3. The remaining difference is the direction movement distance.
4. All the differences in the two directions are added up, and there are two groups in total. Whichever group has the larger value is chosen. The positive or negative determines the direction.
For slow sliding
1. Since the value range of deltaX and deltaY values is very small, they are both retained, but those with different values and directions are also discarded.
2. All the differences in the two directions are added up, and there are two groups in total. Whichever group has the larger value is chosen. The positive or negative determines the direction.
Implement gesture ideas (Gesture)
Based on the above, record deltaX, deltaY and the pairwise difference within a period of time:
deltaX and deltaY are used to count zoom-in and zoom-out gestures.
The pairwise difference is used to count up, down, left and right hand gestures.
Therefore, a gesture is a gesture over a period of time, not a moment in time.
Implementation code
I won’t post the specific code, but you can download it directly from my Github: http://www.php.cn/
Route problem: The deltaX and deltaY values given by mousewheel are quite different from the operation effects, and the fast sliding effect is particularly inaccurate.
Gesture problem: Due to the third point of the two-finger characteristics, the gesture implementation cannot be accurate. Even if the time period is made very short, it will become less accurate due to the amount of data (the idea of calculus cannot be used); As the segments become longer, the reaction time will also become longer;
You can download the code to see the specific effect. The effect is not satisfactory, but you can download it and have a look. If you have a better solution, please tell me, thank you.
The above is the detailed content of js implementation of Mac touchpad two-finger event summary. 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: In this article, this website will introduce to you the relevant content about the Mac keyboard not responding when entering passwords. I hope it will be helpful to you, let’s take a look. How to solve the problem that the password cannot be entered on the Apple Mac system? You can also try to connect this keyboard to other computers to see if it works normally. If the same problem occurs on another computer, it's most likely a fault with the keyboard itself. You may consider replacing the keyboard or repairing it. The first time you log in to Alipay with your Mac computer, you will find the login interface and cannot enter your password. The password input field displays: "Please click here to install the control", so Alipay login requires the installation of security controls. Security controls can encrypt and protect the information you enter (amount, password, etc.) to improve account security. Tie

Many Mac users tend to keep the default name of their device and may never consider changing it. Many people choose to stick with the name from the initial setup, such as "Johnny's MacBook Air" or simply "iMac." Learning how to change the name of your Mac is a very useful skill, especially when you have multiple devices, as it can help you quickly distinguish and manage them. Next, we will teach you step by step how to change the computer name, host name and Bonjour name (local host name) in macOS system. Why should you change your Mac name? Changing the name of your Mac can not only show your personality, but also help improve the user experience: Personalize your Mac: The default name may not be to your taste, change it to a name you like.

Preface: Today, this site will share with you the relevant content about installing pkg files on Mac. If it can solve the problem you are facing now, don’t forget to follow this site and start now! The previous version of macos pkg cannot be installed to upgrade the operating system: If your laptop is using an older operating system version, it is recommended to upgrade to the latest operating system version. Because older versions may not support installation of the latest macOS system. Select "Erase" in Disk Utility, then select the Macos extension in the format, do not check the encryption option, and do not select the apfs format, and finally click the "Erase" button to solve the problem of being unable to complete the macOS installation. Drag the application's icon to the file starting with App

Recently, some friends have consulted the editor about how to set up WeChat Mac to automatically convert voice messages into text. The following is a method for setting up WeChat Mac to automatically convert voice messages into text. Friends in need can come and learn more. Step 1: First, open the Mac version of WeChat. As shown in the picture: Step 2: Next, click "Settings". As shown in the picture: Step 3: Then, click "General". As shown in the picture: Step 4: Then check the option "Automatically convert voice messages in chat to text". As shown in the picture: Step 5: Finally, close the window. As shown in the picture:

Introduction: This article is here to introduce you to the relevant content of cutting files to the hard disk on Mac. I hope it will be helpful to you, let’s take a look. How to Export Photos to a Mobile Hard Drive on a Mac Computer You can use the Finder or Photos application to export photos to a mobile hard drive. When using Finder to export photos, first make sure the mobile hard drive is connected to the Mac and is successfully recognized by the Mac. The steps to transfer photos from Mac to hard drive are simple: first, connect the mobile hard drive to the computer, and then open the [Launcher] icon. Then, find and click the [Photos] icon in the pop-up window. In the opened [Photos] window, hold down the [Shift] key

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

By default, iPhone takes photos from the camera in HEIC format. HEIC stands for High Efficiency Image Container and can hold more pixel data than PNG or JPG files, taking up significantly less space on iPhone storage compared to other formats. These files work best on iPhones but are not widely accepted on the internet because they often result in blurry/grainy pictures when you share them with non-Apple devices. To ensure that HEIC images are compatible on other devices, you may need to convert them to JPG format. This article will introduce how to convert HEIC images to JPG on Mac. How to Convert HEIC Photos to JPG on Mac [3 Methods] Method

Introduction: This article will introduce to you the relevant content about the mac configuration file not taking effect. I hope it will be helpful to you, let's take a look. The solution to the problem that environment variables cannot take effect under Mac. After configuring environment variables in the Mac system, it is found that they are only effective in the current terminal and will become invalid once the terminal is switched. After inquiry, it was found that the Mac system is pre-installed with a tool called ultimate shell-zsh, and the reading of environment variables needs to be set in the .zshrc file. 2. In order for our configuration file to take effect, we can only add the above configuration in .zshrc. If you don’t make the above settings, you will find that it will only take effect every time you source ~/.bash_profile. Re-open z next time.
