87,994
社区成员




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
*{
margin : 0 auto;
padding : 0;
}
#wrap{
width:600px;
height:300px;
border:5px solid black;
overflow:hidden;
}
#srcDiv{
width:800px;
height:300px;
float:left;
}
#cloneDiv{
width:800px;
height:300px;
float:left;
}
.item{
width:100px;
height:300px;
margin:0 50px;
background:red;
float:left;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div id="wrap">
<div style="width:800%;">
<div id="srcDiv">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
<div id="cloneDiv"></div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
var frequency = 5000;
var margin = 200;
var begin = 0;
$("#cloneDiv").html($("#srcDiv").html());
$("#wrap").scrollLeft(0);
function onescroll() {
//推进
if (($("#srcDiv").outerWidth(true) * 2) <= ($("#wrap").scrollLeft() + margin * 3)) {
$("#wrap").scrollLeft(0);
}
begin = $("#wrap").scrollLeft();
var timer1 = setInterval(function () {
if (begin + margin > $("#wrap").scrollLeft()) {
$("#wrap").scrollLeft($("#wrap").scrollLeft() + 10);
console.log($("#wrap").scrollLeft());
} else {
clearInterval(timer1);
$("#wrap").scrollLeft(begin + margin);
console.log($("#wrap").scrollLeft() + "-----------end");
}
}, 30);
}
var timer = setInterval(onescroll, frequency);
});
</script>
</body>
</html>