principleThe principle of anti-shake is: you can trigger an event, but I must execute it n seconds after the event is triggered. If you trigger this event again within n seconds of an event being triggered, I will use the time of the new event as the basis and execute it n seconds later. In short, I will not execute until you trigger the event and no more events are triggered within n seconds. Case<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="utf-8"> <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1"> <title>debounce</title> <style> * { margin: 0; padding: 0; } #container { width: 100%; height: 200px; line-height: 200px; text-align: center; color: #fff; background-color: #444; font-size: 30px; } </style> </head> <body> <div id="container"></div> <script src="debounce.js"></script> </body> </html> function getUserAction(e) { console.log(this); console.log(e); container.innerHTML = count++; }; function debounce(func, wait) { var timeout; return function () { clearTimeout(timeout); timeout = setTimeout(() => { func.apply(this, arguments); // Solve this and event object event }, wait); } } container.onmousemove = debounce(getUserAction, 1000); This is the end of this article about JavaScript anti-shake case study. For more relevant JavaScript anti-shake content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: mysql command line script execution example
>>: MySQL controls the number of attempts to enter incorrect passwords
Background: Make a little progress every day, acc...
Table of contents Preface What is a filter How to...
Preface I recently encountered some problems at w...
1. First look at the request configuration file, ...
A very useful function group_concat(), the manual...
Here are the detailed steps: 1. Check the disk sp...
1: Statement order of grouping function 1 SELECT ...
Table of contents Prerequisites DNS domain name r...
I want to make a page using CSS3 rounded corners ...
It was found in the test that when the page defini...
Visual Studio Code is a powerful text editor prod...
Table of contents 1. Add users 2. Change the user...
By default, MySQL character types are not case-se...
Author | Editor Awen | Produced by Tu Min | CSDN ...
Recent projects involve the creation of a lot of ...