


Use javascript to get the code of the mouse cursor position on the page and the object that triggered the event_javascript skills
Use javascript to get the mouse position:
function mousePosition(ev) {
if (ev.pageX || ev.pageY) {
return {
x: ev.pageX,
y: ev.pageY
};
}
return {
x: ev.clientX document.body.scrollLeft - document.body.clientLeft,
y: ev.clientY document.body.scrollTop - document.body.clientTop
} ;
}
document.onmousemove = mouseMove;
function mouseMove(ev){
ev = ev || window.event;
var mousePos = mousePosition(ev);
}
Detailed description of the code has been introduced in the original text, now go here:
We must first declare an evnet object, which will be activated regardless of movement, click, key press, etc. For an evnet, in Internet Explorer, event is a global variable and will be stored in window.event. In firefox or other browsers, the event will be obtained by the corresponding function. When we assign the mouseMove function to document.onmousemove, mouseMove will get the mouse movement event.
In order for ev to obtain the event event in all browsers, "||window.event" will not work under Firefox because ev already has a value assigned. In MSIE ev is empty, so you get window.event .
Because we need to obtain the mouse position multiple times in this article, we designed a mousePosition function, which contains one parameter: event.
Because we are going to run under MSIE and other browsers, Firefox and other browsers use event.pageX and event.pageY to represent the position of the mouse relative to the document. If you have a 500*500 window and your mouse is in Absolutely in the middle, then the values of pageX and pageY are both 250, and if you scroll down 500, then pageY will become 750.
MSIE is just the opposite. It uses event.clientX and event.clientY to indicate that the mouse is equivalent to the position of the window, not the document. In the same example, if you scroll down 500, clientY is still 250, so we need to add scrollLeft and scrollTop properties relative to the document. Finally, documents in MSIE do not start at 0,0, but usually have a small border (usually 2 pixels). The size of the border is defined in document.body.clientLeft and clientTop. We also add these.
Luckily, we have now solved the coordinate problem using the mousePosition function, so we don’t need to worry about it anymore.
Use javascript to get the object that triggered the event

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

AI Hentai Generator
Generate AI Hentai for free.

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

Detailed explanation of JavaScript string replacement method and FAQ This article will explore two ways to replace string characters in JavaScript: internal JavaScript code and internal HTML for web pages. Replace string inside JavaScript code The most direct way is to use the replace() method: str = str.replace("find","replace"); This method replaces only the first match. To replace all matches, use a regular expression and add the global flag g: str = str.replace(/fi

Leverage jQuery for Effortless Web Page Layouts: 8 Essential Plugins jQuery simplifies web page layout significantly. This article highlights eight powerful jQuery plugins that streamline the process, particularly useful for manual website creation

So here you are, ready to learn all about this thing called AJAX. But, what exactly is it? The term AJAX refers to a loose grouping of technologies that are used to create dynamic, interactive web content. The term AJAX, originally coined by Jesse J

10 fun jQuery game plugins to make your website more attractive and enhance user stickiness! While Flash is still the best software for developing casual web games, jQuery can also create surprising effects, and while not comparable to pure action Flash games, in some cases you can also have unexpected fun in your browser. jQuery tic toe game The "Hello world" of game programming now has a jQuery version. Source code jQuery Crazy Word Composition Game This is a fill-in-the-blank game, and it can produce some weird results due to not knowing the context of the word. Source code jQuery mine sweeping game

Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

This tutorial demonstrates how to create a captivating parallax background effect using jQuery. We'll build a header banner with layered images that create a stunning visual depth. The updated plugin works with jQuery 1.6.4 and later. Download the

This tutorial demonstrates creating dynamic page boxes loaded via AJAX, enabling instant refresh without full page reloads. It leverages jQuery and JavaScript. Think of it as a custom Facebook-style content box loader. Key Concepts: AJAX and jQuery

This JavaScript library leverages the window.name property to manage session data without relying on cookies. It offers a robust solution for storing and retrieving session variables across browsers. The library provides three core methods: Session
