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

Introduction to RHCE bridging, password-free login and port number modification

Table of contents 1. Configure bridging and captu...

Install Kafka in Linux

Table of contents 1.1 Java environment as a prere...

WHMCS V7.4.2 Graphical Installation Tutorial

1. Introduction WHMCS provides an all-in-one solu...

Various methods to implement the prompt function of text box in html

You can use the attribute in HTML5 <input="...

Summary of MySQL's commonly used database and table sharding solutions

Table of contents 1. Database bottleneck 2. Sub-l...

How to use the Linux seq command

1. Command Introduction The seq (Sequence) comman...

A brief introduction to the general process of web front-end web development

I see many novice students doing front-end develop...

Complete steps to install boost library under linux

Preface The Boost library is a portable, source-c...

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

Five delay methods for MySQL time blind injection

Five delay methods for MySQL time blind injection...

Docker container connection implementation steps analysis

Generally speaking, after the container is starte...

Detailed steps for installing MySQL using cluster rpm

Install MySQL database a) Download the MySQL sour...

How to update the view synchronously after data changes in Vue

Preface Not long ago, I saw an interesting proble...