JavaScript MouseEvent Case Study

JavaScript MouseEvent Case Study

MouseEvent

When the mouse performs a certain operation, an event object is generated, which records all the properties of the mouse when the event is triggered.

You can print out the MouseEvent object in the Google console as follows.

function mouseDown(e){
var e = e||event;
console.log(e)
}
window.onload = function (){ 
document.getElementsByTagName('body')[0].addEventListener('mousedown',mouseDown,false)
}

The printed MouseEvent is as follows:

This object has many properties, but the most commonly used ones are offsetX, offsetY, clientX/clientY, pageX, and pageY. What do the various attributes correspond to?

The following are some common events:

altkey: Whether the alt key is pressed when the mouse event is triggered, if so, returns true, otherwise returns false.

button: The event attribute returns an Arabic numeral, 0 represents pressing the left button, 1 represents pressing the scroll wheel, and 2 represents pressing the right button.

offsetX, offsetY: The event attributes return the X and Y coordinates of the mouse relative to the event source element when the event is triggered. Standard events do not have corresponding attributes.

clientX, clientY: The event properties return the horizontal and vertical coordinates of the mouse pointer relative to the browser page (or client area) when the event is triggered.

pageX, pageY: The event attributes return the horizontal and vertical coordinates of the mouse pointer relative to the upper left corner of the entire page when the event is triggered.

screenX, screenY: The event attributes return the horizontal and vertical coordinates of the mouse position relative to the user's screen when the event is triggered. The reference point, or origin, is the upper left corner of the screen.

Well, text descriptions are always annoying, so here’s a classic picture to explain everything:

This is the end of this article about the JavaScript mouse event (MouseEvent) case study. For more relevant JavaScript mouse event (MouseEvent) 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:
  • Detailed explanation of C++ while and do-while statements
  • C language socketpair usage case explanation
  • C# NullReferenceException solution case explanation
  • C# ExecuteScalar() method case explanation
  • C++ basic learning: how to distinguish between references and pointers
  • Two ways to implement stack in C language
  • Use of forEach in Java8 ArrayList
  • Detailed explanation of the C language OutputDebugString and formatted output function OutputDebugPrintf case

<<:  MySQL sliding aggregation/year-to-date aggregation principle and usage example analysis

>>:  Tutorial on deploying nginx+uwsgi in Django project under Centos8

Recommend

Listen directive example analysis in nginx

Plot Review In the previous article, we analyzed ...

Realizing the effect of carousel based on jQuery

This article shares the specific code of jQuery t...

Should I use distinct or group by to remove duplicates in MySQL?

Preface About the performance comparison between ...

Javascript design pattern prototype mode details

Table of contents 1. Prototype mode Example 1 Exa...

Writing a shell script in Ubuntu to start automatically at boot (recommended)

The purpose of writing scripts is to avoid having...

Time zone issues with Django deployed in Docker container

Table of contents Time zone configuration in Djan...

How to isolate users in docker containers

In the previous article "Understanding UID a...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

vue-pdf realizes online file preview

This article example shares the specific code of ...

Detailed explanation of Javascript basics

Table of contents variable Data Types Extension P...

Native JS music player

This article example shares the specific code of ...

What I learned while building my own blog

<br />In one year of blogging, I have person...

Use CSS3 to implement button hover flash dynamic special effects code

We have introduced how to create a waterfall layo...