第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

慕課網(wǎng)課程【JS動畫效果 小節(jié) 6.2完美運動框架】代碼問題請教

慕課網(wǎng)課程【JS動畫效果 小節(jié) 6.2完美運動框架】代碼問題請教

小新在編程 2016-08-21 21:34:34
<!DOCTYPE?html> <html> <head> ????<meta?charset="UTF-8"> ????<title>多物體動畫效果</title> ????<style?type="text/css"> ????*?{ ????????margin:?0; ????????padding:?0; ????} ???? ????ul?li?{ ????????list-style:?none; ????} ???? ????ul?li?{ ????????width:?200px; ????????height:?100px; ????????background-color:?yellow; ????????margin-bottom:?20px; ????????border:?10px?solid?red; ????????opacity:?0.3; ????} ????</style> <script?type="text/javascript"> ????window.onload?=?function()?{ ????????var?arrLi?=?document.getElementsByTagName("li"); ????????for?(var?i?=?0;?i?<?arrLi.length;?i++)?{ ????????????arrLi[i].onmouseover?=?function()?{ ????????????????startMove(this,?{ ????????????????????width:?400, ????????????????????opacity:?70, ????????????????????height:?300, ????????????????}); ????????????}; ????????????arrLi[i].onmouseout?=?function()?{ ????????????????startMove(this,?{ ????????????????????width:?200, ????????????????????opacity:?30, ????????????????????height:?100, ????????????????}); ????????????}; ????????} ????}; ????function?startMove(obj,?json)?{ ????????var?speed; ????????var?icur; ????????clearInterval(obj.timer); ????????obj.timer?=?setInterval(function()?{ ????????????var?flag?=?true; ????????????for?(var?attr?in?json)?{ ????????????????if?(attr?===?"opacity")?{ ????????????????????icur?=?Math.round(parseFloat(getStyle(obj,?attr))?*?100); ????????????????}?else?{ ????????????????????icur?=?parseInt(getStyle(obj,?attr)); ????????????????} ????????????????speed?=?(json[attr]?-?icur)?/?10; ????????????????speed?=?speed?>?0???Math.ceil(speed)?:?Math.floor(speed); ????????????????console.log("屬性"?+?attr?+?":"?+?json[attr]?+?"---icur:"?+?icur); ????????????????if?(json[attr]?!=?icur)?{ ????????????????????flag?=?false; ????????????????} ????????????????if?(attr?===?"opacity")?{ ????????????????????obj.style.opacity?=?(icur?+?speed)?/?100; ????????????????????//?obj.style.filter?=?"alpha(opacity:"?+?(icur?+?speed)?+?")"; ????????????????}?else?{ ????????????????????obj.style[attr]?=?icur?+?speed?+?"px"; ????????????????} ????????????????if?(flag)?{ ????????????????????clearInterval(obj.timer); ????????????????} ????????????} ????????},?30); ????} ????function?getStyle(obj,?attr)?{ ????????if?(obj.currentStyle)?{ ????????????return?obj.currentStyle[attr]; ????????}?else?{ ????????????return?getComputedStyle(obj,?null)[attr]; ????????} ????} ????</script> ????</head> <body> ????<ul> ????????<li></li> ????????<li></li> ????????<li></li> ????</ul> </body> </html>這段代碼執(zhí)行到for中, 有一個屬性到達(dá)了目標(biāo)值, 比如width=400, 然后這個時候for遍歷結(jié)束了, ?然后再次執(zhí)行setInterval()部分, 又遍歷for, 進(jìn)去flag剛開始是true 遇到width=400,不執(zhí)行這段代碼if (json[attr] != icur) {? ? ? ? ? ? ? ? ? ? flag = false;? ? ? ? ? ? ? ? }flag 依舊為true, 這個時候清楚interval. 請問會不會這樣需要把if (flag) {? ? ? ? ? ? ? ? ? ? clearInterval(obj.timer);? ? ? ? ? ? ? ? }這段代碼寫在for{}后嗎? ?請問該怎么解決? ?謝謝給位【碼友】
查看完整描述

2 回答

?
stone310

TA貢獻(xiàn)361條經(jīng)驗 獲得超191個贊

必須要放在for(){}后面,你這里寫的是放在for里面了,目前情況執(zhí)行沒有問題,但是目標(biāo)值改下就會出問題

arrLi[i].onmouseover?=?function()?{
????????????????startMove(this,?{
????????????????????width:?400,???//將400改成201

寫在for里面其實跟沒寫一樣,當(dāng)遍歷到其中一個達(dá)到目標(biāo)值,就全部停止,所以要放到for遍歷外

查看完整回答
反對 回復(fù) 2016-08-30
  • 2 回答
  • 0 關(guān)注
  • 1755 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號