<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鼠标悬浮时改变样式</title>
<style>
#div1{
width: 300px;
height: 500px;
display: flex;
justify-content: center;
color: white;
}
.a{
width: 100px;
height: 40px;
background-color: #cccccc;
border: 1px solid #cccccc;
margin: 1px;
border-radius: 25px 25px 0px 0px;
line-height: 40px;
text-align: center;
}
</style>
</head>
<body>
<div id="div1">
<div class="a">左侧DIV</div>
<div class="a">中间DIV</div>
<div class="a">右侧DIV</div>
</div>
</body>
<script src="../../js/jquery-3.1.1.min.js"></script>
<script>
$("#div1 div:first-child").mouseover(function () {
$(this).css("background-color","red");
}).mouseout(function () {
$(this).css("background-color","#cccccc");
})
$(" div + div").mouseover(function () {
$(this).css("background-color","red");
}).mouseout(function () {
$(this).css("background-color","#cccccc");
})
$("#div1 div:last-child").mouseover(function () {
$(this).css("background-color","red");
}).mouseout(function () {
$(this).css("background-color","#cccccc");
})
</script>
</html>
H5基础知识第十四课时(用JQuery实现鼠标悬浮时改变样式)
最新推荐文章于 2022-09-21 15:49:30 发布