日期:2014-05-16 浏览次数:20591 次
<!DOCUTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<style type="text/css">
.container{position:relative;height:90px;width:100px;overflow:hidden;}
.container .child{float:left;}
.contoller ul li{float:left;list-style:none;border:1px solid #444;padding:2px;margin-left:5px;}
</style>
</head>
<body>
<div class="container">
<div class="child">aaaaaaaaaaaaaa</div>
<div class="child">bbbbbbbbbbbbbb</div>
<div class="child">cccccccccccccc</div>
<div class="child">dddddddddddddd</div>
</div>
<div style="clear:both"></div>
<div class="contoller">
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
<li>ddd</li>
</ul>
</div>
<script type="text/javascript">
$(function(){
var html = $('.container').html();
var per = $('.child').height();
var height = per*4;
$('.container').height(height);
$('.container').html(html+html);
$('.contoller ul li').click(function(){
var idx = $(this).index();
var old = $('.container').scrollTop();
$('.container').animate({scrollTop:per*idx},200,function(){
if(per*idx==height){
$('.container').scrollTop(0);
}
})
})
})
</script>
</body>
</html>
<html>
<head>
<style>