在html5页面中,一个div或者图片,鼠标移动上去的时候变大,移出的时候又变回原样怎么弄,

求大神,求高手,要又代码

这里介绍两种方式:

一:通过css样式中的 ":hover"实现,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
background:red;
width:200px;
height:200px;
}
div:hover{
background:red;
width:500px;
height:500px;
}
</style>
</head>
<body>
<div>变大</div>
</body>
</html>

二:通过javascript方式实现,代码如下

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
background:red;
width:200px;
height:200px;
}
.divs{
background:red;
width:500px;
height:500px;
}
</style>
</head>
<body>
<div>变大</div>
<script>
// 首先获取div元素
var divs = document.getElementsByTagName('div')[0];
//鼠标移入,将divs的className样式赋给该标签
divs.onmouseover = function () {
this.className = "divs";
}
//鼠标移出,将空的className样式赋给该标签
divs.onmouseout = function () {
this.className = "";
}
</script>
</body>
</html>

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答