Home > Web Front-end > JS Tutorial > body text

Several implementation methods of onmouseover and onmouseout to switch pictures when the mouse moves in and out

青灯夜游
Release: 2018-10-10 16:01:55
forward
9478 people have browsed it

This article introduces to you several implementation methods of onmouseover and onmouseout to move the mouse in and out to switch pictures. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

It is very common to move the mouse in and out to switch images, so let’s talk about how to implement it:

The first method, which is also the simplest one, can be implemented in html

<img class="img" src="img/dongtai.png" onmouseover="this.src=&#39;img/HBuilder.png&#39;" onmouseout="this.src=&#39;img/dongtai.png&#39;"/>
Copy after login

First default a picture, and then write the picture to move in and out.

The second method, js replacement

<img name="image1" src="img/dongtai.png" onmouseover="mouseOver()" onmouseout="mouseOut()" />
Copy after login
function mouseOver() {
	document.image1.src = "img/HBuilder.png"
}

function mouseOut() {
	document.image1.src = "img/dongtai.png"
}
Copy after login

Write the method of replacing the image in js and call it in html.

If you don’t use onmouseover and onmouseout, you can also write like this

<p class="bg"></p>
Copy after login
.bg{background: url(img/HBuilder.png) no-repeat;height: 300px;}
.bg:hover{background: url(img/dongtai.png) no-repeat;}
Copy after login

These three methods can achieve the effect of moving the mouse in and out of the picture. Isn’t it very simple? You can try it!

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study. For more related tutorials, please visit JavaScript Video Tutorial!

Related recommendations:

php public welfare training video tutorial

JavaScript graphic tutorial

JavaScriptOnline Manual

The above is the detailed content of Several implementation methods of onmouseover and onmouseout to switch pictures when the mouse moves in and out. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template