JS新手,做了一个div无缝移动的代码,需要鼠标移入的时候清除定时器,可是鼠标移入后定时器为什么不停止?谢谢
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
#container{width:200px;height:50px;background-color: rosybrown;position:relative;overflow:hidden;}
#parent{width:400px;height:50px;background-color:red;position:absolute;}
.children{width:46px;height:50px;display:inline-block;background-color:deepskyblue ;text-align:center;vertical-align:center; }
</style>
<script>
window.onload=function() {
var b = 0
var c = setInterval(m, 80)
function m() {
var a = document.getElementById("parent")
if (b >= -200) {
b = b - 1
a.style.left = b + "px"
}
else {
b = 0
}
}
var ochi = document.getElementById("parent")
ochi.onmouseover = clearInterval(c)
ochi.onmouseout = setInterval(m, 80)
}
<body>
<div id="container">
<div id="parent">
<div class="children" >1</div>
<div class="children" >2</div>
<div class="children" >3</div>
<div class="children" >4</div>
<div class="children" >1</div>
<div class="children" >2</div>
<div class="children">3</div>
<div class="children">4</div>
</div>
</div>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…