Js process of operating mouse events
In actual projects, we often need to use JavaScript to operate mouse events. So today I will tell you in detail the process of operating mouse events with JS and how to use JS to operate mouse events.
Noteonmouseover and onmouseout are executed only once, while onmousemove is executed multiple times
OnmousedownIt is also executed only once, only once for each click, and will not be triggered continuously. Unlike onkeydown and onkeypress, it is very messy here. What are the mouse events? ? ?
It displays as undefined in Firefox
It displays as undefined in IE
But the above display is normal in Google. Now we need to make a compatible one IE and Firefox
There is a question here. In a separate console.log(window), the event attribute seen in it is undefined, but in consoe.log(window.event), the event attribute is displayed. Why is there such a difference in the effect you want?
This is where the teacher struggles, but I don’t know why.
The above analysis is wrong. In Google, both e and window.event are supported. Firefox only supports e, and Google only supports window.event
Pass to participate in dynamically created attributes
Since the attributes e.pageX and e.pageY are not supported in lower versions of IE, (in lower versions of IE (displayed in the middle), so use the mouse position of the visual area + the scroll bar curl height to obtain the mouse position based on the content area.
The document above is the window
Event capture is just to understand the content. In IE The
event processing function is not supported. Note that events following level 0 events will overwrite previous events. This is very important.
Window can be omitted. The above code makes no sense
Bubbling: from specific nodes to unspecific nodes
Now it represents capture, but it has no specific effect. Now it is the same as bubbling
Capture: from non-specific nodes to specific nodes
Achieve the same effect as the function execution context, addEventListener() is not supported in IE browser
The above is Method of unloading DOM level 0 events (unloading events, if the interface is refreshed again, the event processing function will continue to be executed)
In fact, it has the same effect as unloading DOM level 0 events
IE Add DOM2-level events
The latest version of IE, IE11, does not support the attribute attachEvent
IE uninstalls DOM2-level events
The following is the encapsulation function:
This This way of writing is displayed as empty in IE
This way of writing will directly report an error in non-IE.
The display in non-IE is a function, and the display in IE is undefined. The following function encapsulation is Carry out based on this principle
Since event capture is rarely used, the fourth value is usually false. There is no need to pass a separate parameter and it is directly hardcoded
when uninstalling , cannot be used in event handling functionsAnonymous functions
Pay attention to the execution order in the IE version
DOMContentLoaded is now to understand the content, pay attention to a concept: event handling function
I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!
Related reading:
How to make DIV adaptive height
How to use CSS to hide the text content of the image background
The necessity of initializing CSS before starting the front-end project
The above is the detailed content of Js process of operating mouse events. 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

How to use WebSocket and JavaScript to implement an online speech recognition system Introduction: With the continuous development of technology, speech recognition technology has become an important part of the field of artificial intelligence. The online speech recognition system based on WebSocket and JavaScript has the characteristics of low latency, real-time and cross-platform, and has become a widely used solution. This article will introduce how to use WebSocket and JavaScript to implement an online speech recognition system.

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

With the popularity of mobile Internet, Toutiao has become one of the most popular news information platforms in my country. Many users hope to have multiple accounts on the Toutiao platform to meet different needs. So, how to open multiple Toutiao accounts? This article will introduce in detail the method and application process of opening multiple Toutiao accounts. 1. How to open multiple Toutiao accounts? The method of opening multiple Toutiao accounts is as follows: On the Toutiao platform, users can register accounts through different mobile phone numbers. Each mobile phone number can only register one Toutiao account, which means that users can use multiple mobile phone numbers to register multiple accounts. 2. Email registration: Use different email addresses to register a Toutiao account. Similar to mobile phone number registration, each email address can also register a Toutiao account. 3. Log in with third-party account

In today's fast-paced society, sleep quality problems are plaguing more and more people. In order to improve users' sleep quality, a group of special sleep anchors appeared on the Douyin platform. They interact with users through live broadcasts, share sleep tips, and provide relaxing music and sounds to help viewers fall asleep peacefully. So, are these sleep anchors profitable? This article will focus on this issue. 1. Are Douyin sleep anchors profitable? Douyin sleep anchors can indeed earn certain profits. First, they can receive gifts and transfers through the tipping function in the live broadcast room, and these benefits depend on their number of fans and audience satisfaction. Secondly, the Douyin platform will give the anchor a certain share based on the number of views, likes, shares and other data of the live broadcast. Some sleep anchors will also

JavaScript and WebSocket: Building an efficient real-time weather forecast system Introduction: Today, the accuracy of weather forecasts is of great significance to daily life and decision-making. As technology develops, we can provide more accurate and reliable weather forecasts by obtaining weather data in real time. In this article, we will learn how to use JavaScript and WebSocket technology to build an efficient real-time weather forecast system. This article will demonstrate the implementation process through specific code examples. We

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

jQuery is a popular JavaScript library that can be used to simplify DOM manipulation, event handling, animation effects, etc. In web development, we often encounter situations where we need to change event binding on select elements. This article will introduce how to use jQuery to bind select element change events, and provide specific code examples. First, we need to create a dropdown menu with options using labels:

Introduction to the method of obtaining HTTP status code in JavaScript: In front-end development, we often need to deal with the interaction with the back-end interface, and HTTP status code is a very important part of it. Understanding and obtaining HTTP status codes helps us better handle the data returned by the interface. This article will introduce how to use JavaScript to obtain HTTP status codes and provide specific code examples. 1. What is HTTP status code? HTTP status code means that when the browser initiates a request to the server, the service
