<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
*{
margin:0;
padding:0;
}
div{
600px;
height:200px;
position:relative;
border:1px solid red;
margin:100px;
overflow:hidden;
}
ul{
600%;
position:absolute;
left:0;
}
li{
float:left;
list-style:none;
}
</style>
<body>
<div id="box">
<ul id="u">
<li><img src="a.jpg" alt="" /></li>
<li><img src="b.jpg" alt="" /></li>
<li><img src="c.jpg" alt="" /></li>
<li><img src="d.jpg" alt="" /></li>
<li><img src="a.jpg" alt="" /></li>
<li><img src="b.jpg" alt="" /></li>
</ul>
</div>
</body>
</html>
<script src="../public.js"></script>
<script>
/*
思路: 如果可视区显示两张图片,赋值第一张第二张图片到所有图片的结尾处
*/
var num = 0;//操作left值的变化
var timer = setInterval(autoPlay,20);
function autoPlay(){
if( num < -1200 ){
num = 0;
}else{
num--;
}
$id("u").style.left = num+"px";
}
//鼠标移入到大容器上 停止定时器
$id("box").onmouseover = function(){
clearInterval(timer);
}
//鼠标离开启动定时器
$id("box").onmouseout = function(){
timer = setInterval(autoPlay,20);
}
</script>