案例分析
♥.鼠标经过某个小li 有两步操作
1.当前小li 宽度变为 224px, 同时里面的小div淡出,大div淡入
2.其余兄弟小li宽度变为69px, 小div淡入, 大div淡出
效果展示
完整代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery.min.js"></script>
<style>
body {
background-color: #ccc;
font-size: 20px;
margin: 100px;
}
* {
margin: 0;
padding: 0;
}
li {
list-style-type: none;
}
.box {
height: 69px;
background-color: bisque;
overflow: hidden;
}
.box li {
position: relative;
float: left;
width: 69px;
height: 69px;
margin-right: 20px;
}
li.current {
width: 224px;
}
li.current .small {
display: none;
}
li.current .big {
display: block;
}
a .small {
position: absolute;
top: 0;
height: 0;
width: 69px;
height: 69px;
}
a .big {
width: 224px;
height: 69px;
display: none;
}
</style>
</head>
<body>
<script>
$(function() {
// 鼠标经过某个小li 有两步操作:
$(".box li").mouseover(function() {
// 1.当前小li 宽度变为 224px, 同时里面的小div淡出,大div淡入
$(this).stop().animate({
width: 224
}).find(".small").stop().fadeOut().siblings(".big").stop().fadeIn();
// 2.其余兄弟小li宽度变为69px, 小div淡入, 大div淡出
$(this).siblings().stop().animate({
width: 69
}).find(".small").stop().fadeIn().siblings(".big").fadeOut();
});
});
</script>
<div class="box">
<ul>
<li class="current">
<a href="javascript:;">
<div class="small" style="background-color: pink;"></div>
<div class="big" style="background-color: red;"></div>
</a>
</li>
<li>
<a href="javascript:;">
<div class="small" style="background-color: pink;"></div>
<div class="big" style="background-color: blue;"></div>
</a>
</li>
<li>
<a href="javascript:;">
<div class="small" style="background-color: pink;"></div>
<div class="big" style="background-color: orange;"></div>
</a>
</li>
</ul>
</div>
</body>
</html>