<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
padding:0;
margin:0;
}
ul,ol{
list-style: none;
}
.box{
width: 900px;
height: 300px;
border:1px solid #333;
margin:50px auto;
position: relative;
overflow: hidden;
}
.box ul li{
position: absolute;
width: 560px;
height: 300px;
top:0px;
}
.box ul li.no0{
left:0px;
}
.box ul li.no1{
left:180px;
}
.box ul li.no2{
left:360px;
}
.box ul li.no3{
left:540px;
}
.box ul li.no4{
left:720px;
}
</style>
</head>
<body>
<div class="box" id="box">
<ul>
<li class="no0"><a href=""><img src="images/0.jpg" alt=""></a></li>
<li class="no1"><a href=""><img src="images/1.jpg" alt=""></a></li>
<li class="no2"><a href=""><img src="images/2.jpg" alt=""></a></li>
<li class="no3"><a href=""><img src="images/3.jpg" alt=""></a></li>
<li class="no4"><a href=""><img src="images/4.jpg" alt=""></a></li>
</ul>
</div>
<script type="text/javascript" src="js/jquery-1.12.3.min.js"></script>
<script type="text/javascript">
$(".no0").mouseenter(function(){
// 防流氓
$("li").stop(true);
$(".no1").animate({"left":560},500);
$(".no2").animate({"left":560 + 85},500);
$(".no3").animate({"left":560 + 85 * 2},500);
$(".no4").animate({"left":560 + 85 * 3},500);
});
$(".no1").mouseenter(function(){
// 防流氓
$("li").stop(true);
$(".no1").animate({"left":85},500);
$(".no2").animate({"left":560 + 85},500);
$(".no3").animate({"left":560 + 85 * 2},500);
$(".no4").animate({"left":560 + 85 * 3},500);
});
$(".no2").mouseenter(function(){
// 防流氓
$("li").stop(true);
$(".no1").animate({"left":85},500);
$(".no2").animate({"left":85 * 2},500);
$(".no3").animate({"left":560 + 85 * 2},500);
$(".no4").animate({"left":560 + 85 * 3},500);
});
$(".no3").mouseenter(function(){
// 防流氓
$("li").stop(true);
$(".no1").animate({"left":85},500);
$(".no2").animate({"left":85 * 2},500);
$(".no3").animate({"left":85 * 3},500);
$(".no4").animate({"left":560 + 85 * 3},500);
});
$(".no4").mouseenter(function(){
// 防流氓
$("li").stop(true);
$(".no1").animate({"left":85},500);
$(".no2").animate({"left":85 * 2},500);
$(".no3").animate({"left":85 * 3},500);
$(".no4").animate({"left":85 * 4},500);
});
// 鼠标离开大盒子,所有的li恢复原状。
$("#box").mouseleave(function(){
$("li").stop(true);
$(".no1").animate({"left":180},300);
$(".no2").animate({"left":360},300);
$(".no3").animate({"left":540},300);
$(".no4").animate({"left":720},300);
});
</script>
</body>
</html>
jQuery - 手风琴效果 -
最新推荐文章于 2019-06-17 09:48:00 发布