<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>多banner效果</title>
<meta name="keywords" content="" />
<meta name="description" content="" /> <style>
*{margin:0;padding:0;}
ul,li{list-style:none;}
.banner{width:280px;height:210px;margin:20px auto;overflow:hidden;position:relative;}
.banner .bannerul li{width:280px;height:210px;}
.banner .prev,.next{display:block;width:30px;height:50px;color:#fff;font-size:22px;
background:rgba(0,0,0,0.5);position:absolute;top:85px;text-decoration:none;
text-align:center;line-height:50px;
}
.banner .prev{left:0;}
.banner .next{right:0;}
</style>
</head>
<body> <div class="banner">
<ul class="bannerul">
<li><img src="data:images/337622.jpg" /></li>
<li><img src="data:images/335897.jpg" /></li>
<li><img src="data:images/336767.gif" /></li>
</ul>
<a href="#" class="prev"><</a>
<a href="#" class="next">></a>
</div> <div class="banner">
<ul class="bannerul">
<li><img src="data:images/337622.jpg" /></li>
<li><img src="data:images/335897.jpg" /></li>
<li><img src="data:images/336767.gif" /></li>
</ul>
<a href="#" class="prev"><</a>
<a href="#" class="next">></a>
</div> <div class="banner">
<ul class="bannerul">
<li><img src="data:images/337622.jpg" /></li>
<li><img src="data:images/335897.jpg" /></li>
<li><img src="data:images/336767.gif" /></li>
</ul>
<a href="#" class="prev"><</a>
<a href="#" class="next">></a>
</div> <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
$(function(){ var $li = $(".bannerul").find("li"); var $lastli = $li.last().clone();
var $firstli = $li.first().clone();
$(".bannerul").append($firstli);
$(".bannerul").prepend($lastli); var $lih = $li.height();
var $len = $li.length/$(".banner").find(".bannerul").length; $(".bannerul").css({"marginTop":$lih*-1}); $(".next").click(function(){ var $ul = $(this).parent(".banner").find(".bannerul"); var index = ($ul.data("index"))||1;
index ++;
$ul.stop(true,true).animate({"marginTop":index*$lih*-1},function(){
if(index==$len+1){
$(this).css({"marginTop":$lih*-1});
index = 1;
}
$ul.data("index",index);
}); }); $(".prev").click(function(){
var $ul = $(this).parent(".banner").find(".bannerul");
var index = ($ul.data("index"))||1;
index --; $ul.stop(true,true).animate({"marginTop":index*$lih*-1},function(){
if(index==0){
$(this).css({"marginTop":$len*$lih*-1});
index = $len;
}
$ul.data("index",index);
}); });
}); </script> <!--
337622.jpg
335897.jpg
336767.gif
334732.jpg
333308.png
-->
</body>
</html>