亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

JS緩沖動畫中為什么會卡住閃動?

<!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" />

<title>無標題文檔</title>

<style>


*{margin:0; padding:0}

.bigBox

{

width:200px;?

height:200px;?

left: -200px;

top:120px;?

background:red;

position:relative;

opacity:30;

}

span

{

width: 20px;

height: 50px;

background: blue;

position: absolute;

left: 200px;

top: 75px;

}


</style>

<script type="text/javascript" >


window.onload=function()

{

var movebigBox=document.getElementById("big");

var timerId = null;

movebigBox.onmouseover=function(){moveFun(0)};

movebigBox.onmouseout=function(){moveFun(-200)};

function moveFun(target)

{

clearInterval(timerId);

? ?var timerId=setInterval(function move()

{ ?

? var speed=(target-movebigBox.offsetLeft)/20;

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

? if(movebigBox.offsetLeft==target)

{

clearInterval(timerId);

}

else

{?

//document.title=speed;

movebigBox.style.left ?= movebigBox.offsetLeft+speed+"px";

}

},30);

}

}


</script>

</head>

<body>

? <div class="bigBox" id="big" >

? <span>分享</span>

? </div>

</body>

</html>


正在回答

2 回答

你的這句話寫錯了:

?var?timerId=setInterval(function?move()

你先前已經定義過了,但是你這里又重新定義了一遍,但是javascript的運行是從上到下的,他認為你重新定義了一個新的timerId,簡單說你去掉這個var就正常了,改成這樣:

timerId=setInterval(function?move()


0 回復 有任何疑惑可以回復我~
#1

慕粉studying 提問者

非常感謝!
2016-11-07 回復 有任何疑惑可以回復我~

說實話? 我都聽不懂你的問題? 卡住閃動?

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
JS動畫效果
  • 參與學習       113918    人
  • 解答問題       1502    個

通過本課程JS動畫的學習,從簡單動畫開始,逐步深入各種動畫框架封裝

進入課程

JS緩沖動畫中為什么會卡住閃動?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號