关于JS无缝滚动图片的问题

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title></title>
</head>

<body>

</body>

</html>
<style type="text/css">
#user_bg {
width: 300px;
height: 200px;
float: left;
position: relative;
margin: 0 auto;
overflow: hidden;
margin-left: 20px;
background: #ccc;
}

.user_btn {
width: 50px;
height: 50px;
float: left;
margin-top: 80px;
margin-left: 20px;
background: #ccc;
}

ul {
position: absolute;
margin: 0;
padding: 0;
left: 0;
top: 0;
}

li {
width: 300px;
height: 200px;
float: left;
background: red;
list-style: none;
}
</style>
<script type="text/javascript">
window.onload = function() {
var btn= document.getElementsByClassName('user_btn');
var oDiv = document.getElementById('user_bg');
var oUl = oDiv.getElementsByTagName('ul')[0];
var aLi = oUl.getElementsByTagName('li');
var str=oUl.innerHTML+oUl.innerHTML;
oUl.style.width = aLi[0].offsetWidth * aLi.length*2 + 'px';
oUl.innerHTML=str;
var speed=5;
var timer=null;
function Move()
{
oUl.style.left=oUl.offsetLeft-speed+'px';
if (oUl.offsetLeft<-oUl.offsetWidth/2){
oUl.style.left='0px';
}
}
timer=setInte rval(Move, 30);

oUl.onmouseover=function(){
clearInterval(timer);
}
oUl.onmouseout=function(){
setInterval(Move, 30);
}
}
</script>
<div class="user_btn"></div>
<div id="user_bg">
<ul>
<li style="background: red;">1</li>
<li style="background: green;">2</li>
<li style="background: yellow;">3</li>
</ul>
</div>
<div class="user_btn"></div>
为啥执行之后鼠标移入停止,移出继续,然后再移入就无效了,并且图片移动的速度加快!哪里出错啦!?

setInterval(Move, 30);这句话换成timer=setInterval(Move, 30);
温馨提示:答案为网友推荐,仅供参考
相似回答