Home Web Front-end HTML Tutorial What is the difference between onmouseover and hover in CSS?

What is the difference between onmouseover and hover in CSS?

Jun 28, 2017 am 10:50 AM
hover

hover includes the process of moving the mouse onto the object and moving the mouse out of the object at the same time, and the corresponding subclass is also selected.

Mouseover means that when the mouse passes over an object, all subclasses that do not include it are selected at the same time.

The main difference is that event drivers are also added to the subclasses of hover elements. And mouseover only adds event driver to the current element.

And the hover event includes the mouseover event


mousemove(fn);

Bind a handler function to the mousemove event of each matching element.

hover(over, out);

A method that simulates hover events (the mouse moves over and out of an object). This is a custom method that provides a "keep in it" state for frequently used tasks.

When the mouse moves over a matching element, the specified first function will be triggered. When the mouse moves out of this element, the specified second function will be triggered. Moreover, it will be accompanied by detection of whether the mouse is still in a specific element (detection of subclasses). If so, it will continue to remain in the "hover" state without triggering the move-out event (mouseout).

$("td").hover( function () { $(this).addClass("hover"); }, function () { $(this).removeClass("hover"); });

There is such a paragraph in the jquery source code:
hover: function( fnOver, fnOut ) {
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
}

That is to say hover! = mouseover+mouseout. But hover=mouseenter + mouseleave.

In the past, I only knew that pseudo-classes like hover, link, visited and active could only be applied to the a tag, that is, they should be written as a:hover, a:link, a:visited, a:active. In fact, these four things can be applied to other html tags and classes assigned to other definitions.

For information about CSS pseudo-classes, please refer to: http://www.w3school.com.cn/css/css_pseudo_classes.asp

a:link {color: #FF0000} /* Not visited Link*/

a:visited {color: #00FF00} /* Visited link*/

a:hover {color: #FF00FF} /* Move the mouse to the link* /

a:active {color: #0000FF} /* Selected link*/


The above is the detailed content of What is the difference between onmouseover and hover in CSS?. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CSS tip: Use transition to retain hover state CSS tip: Use transition to retain hover state Sep 27, 2022 pm 02:01 PM

How to preserve hover state? The following article will introduce to you how to retain the hover state without using JavaScript. I hope it will be helpful to you!

Experience is flying. Take a flight with Haval X1 camera Experience is flying. Take a flight with Haval X1 camera Jan 15, 2024 pm 02:21 PM

We can often see a lot of wonderful top-down videos on the Internet. The pictures taken by drones are indeed quite shocking. However, in fact, many people have limited understanding of drones. For example, why can they still fly in some places where flying is restricted? In fact, ready-to-fly “drones” are the current mainstream, and they are more worthy of most people’s choice. Today I will give you a hands-on experience with the Harvest Flying Camera X1. In terms of appearance, the Harvest Flying Camera X1 has the first folding design. The whole camera is only 125g, which is lighter than a mobile phone. After folding, it can be easily held in the hand and put into a bag without any pressure. Four soft dyed leaves and safety frame design perfectly protect the safety of shooting. Dyed Leaf innovatively uses Biobased biological substrate, which is highly elastic, durable, safe and environmentally friendly; it also has a fully protective frame to protect your hands during takeoff and landing.

How to remove the hover event in css How to remove the hover event in css Feb 01, 2023 am 10:06 AM

Methods to remove css hover events: 1. Through "$("a").hover(function(){ alert('mouseover'); }, function(){ alert('mouseout'); })" method to bind the hover event; 2. Unbind the hover event through the "$('a').off('mouseenter').unbind('mouseleave');" method. Can.

The role of hover in html The role of hover in html Feb 20, 2024 am 08:58 AM

The role of hover in HTML and specific code examples In web development, hover refers to triggering some actions or effects when the user hovers the cursor over an element. It is implemented through the CSS :hover pseudo-class. In this article, we will introduce the role of hover and specific code examples. First, hover enables an element to change its style when the user hovers over it. For example, when hovering the mouse over a button, you can change the button's background color or text color to remind the user what to do next.

Why is hover a pseudo element? Why is hover a pseudo element? Oct 09, 2023 pm 05:45 PM

Hover is not a pseudo-element, it is a pseudo-class. Pseudo-classes are used to select a specific state or behavior of an element, while pseudo-elements are used to add styles to specific parts of an element. Because :hover is used to select a specific state of an element rather than adding styles to a specific part of the element, you can use the :hover pseudo-class to style the mouseover state of an element, and you can use the :hover pseudo-class to add hover effects to links. The link's color, background color, etc. can change when the mouse hovers over it.

How to use hover in css How to use hover in css Feb 23, 2024 pm 12:06 PM

The hover pseudo-class in CSS is a very commonly used selector that allows us to change the style of an element when the mouse is hovering over it. This article will introduce the usage of hover and provide specific code examples. 1. Basic Usage To use hover, we need to first define a style for the element, and then use the :hover pseudo-class to specify the corresponding style when the mouse is hovering. For example, we have a button element. When the mouse hovers over the button, we want the background color of the button to change to red and the text color to white.

How to use hover in css How to use hover in css Nov 24, 2023 am 10:32 AM

In CSS, :hover is a pseudo-selector used to select elements that the mouse pointer is hovering over. You can use :hover to apply some style changes when the user hovers over an element.

How to use jQuery hover() method How to use jQuery hover() method Dec 04, 2023 am 09:56 AM

hover() is a commonly used method in jQuery. It is used to bind two event handling functions. These two functions will be executed when the mouse pointer enters and leaves the matching element. The basic usage method is "$(selector).hover(inFunction,outFunction);".

See all articles