How to achieve discoloration effect on mouse hover in javascript

青灯夜游
Release: 2022-01-18 18:15:43
Original
9881 people have browsed it

Javascript method to implement mouseover discoloration: 1. Bind the element to the onmouseover event and set the event processing function; 2. In the event processing function, use "element object.style.color attribute name="color The value ";" statement sets the effect of the element's color change when a hover event is triggered.

How to achieve discoloration effect on mouse hover in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Idea: For upper-level elements and parent elements, lower-level elements and child elements can change color. Just :hover and css selectors are all it takes. Subordinate elements operate on superior elements by using the onmouseover and onmouseout events in JavaScript

  • The onmouseover event occurs when the mouse pointer moves to the specified element.

  • The onmouseout event occurs when the mouse pointer moves out of the specified object.

1. HTML code

 
鼠标移动到 A div 时,我要变色

一号 div
二号 div
Copy after login

2. JavaScript code

Note: It is recommended to write it before the closing tag of the body

Copy after login

3. CSS code

Copy after login

4. Rendering

How to achieve discoloration effect on mouse hover in javascript

How to achieve discoloration effect on mouse hover in javascript

##[Related recommendations:

javascript learning tutorial

The above is the detailed content of How to achieve discoloration effect on mouse hover in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!