猿问

js多物体运动中的问题

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>多物体运动</title>

<style>

*{

margin:0;

padding:0;

}

div{

width:200px;

height:100px;

background:#abc;

margin-bottom: 20px;

}

</style>

</head>

<body>

<div></div>

<div></div>

<div></div>

<script>

window.onload = function(){

var iDiv = document.getElementsByTagName("div");

for(var i = 0 ;i < iDiv.length;i++){

iDiv[i].onmouseover = function(){

startMove(this,400);

};

iDiv[i].onmouseout = function(){

startMove(this,200);

};

}

};

function startMove(obj,destination){

clearInterval(obj.timer);    //将此处改为 obj.timer = null;为什么运行之后在为到达目的地时候鼠标移除div会抽搐

obj.timer = setInterval(function(){

var speed = (destination - obj.offsetWidth)/8;

speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);

if(destination == obj.offsetWidth){

clearInterval(obj.timer);

}else{

obj.style.width = obj.offsetWidth + speed +"px";

},30);


}

</script>

</body>

</html>


前端小学生a
浏览 1064回答 0
0回答

慕瓜9220888

YMCJISOLMXJDSVHRPJGKHMFMQXUNFBBAYYXHTHRGPWYOYTOHDJBLZMCXCFVBZMTHSYUNXYZDYAPLIPCDUBZPCSCDXOTEARAKLFMSMVBKBFGMJXMCSZZUFDYWVOPFQHQIHTWTMMUUPEUISZDOTXUBJGXBHJDTWQKLLPQSBAANUYIZETPFCMRLDIHTKBIWDJXHXHBFSDVXDWFVAHBEPKKTJKRBTHHQGABBPSDLDAQRIIDIEUUSZTHVWCRSZXBYAVBXTRHXAYTYUXUOJCZAXHIYZGNNLJSLPWAAZHEOSASCKKDTIRYGRHMAOVVAMHFKLOONHOSTKSIUGRIIRTPOAGURIFJNTJYPDQHODACZQTAOLCIODEOVMAOOHTOZTBARUJEYPFZFDPLEIJDMBHQQPZQLGIDCMBCPNNWAMCBSNAEKLJZIOZWXUADKNKLSSCBAAVWQBMPAJIMXKARUYIEXIYCJEZSHNNKRBPTTQCDEYIWONWVZDMTHCYNNDWNBFKTPNHRPCGVRHAKELCVQWVLRDOZINTF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KESKCCAELBFLHQSLCJAZ

qq_冲哥_0

为什么要把clearInterval(obj.timer); 改为 obj.timer = null? 用意何在
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答