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

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

Bstop有關(guān)代碼里面這個(gè)的應(yīng)用不太懂,if(cur!=json[attr]) Bstop=false;這個(gè)看不太懂

Bstop有關(guān)代碼里面這個(gè)的應(yīng)用不太懂,if(cur!=json[attr]) Bstop=false;這個(gè)看不太懂

Youruncle 2016-08-17 11:23:06
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> div { width: 200px; height: 200px; background: red; filter: alpha(opacity: 30); opacity: 0.3; } </style> <script type="text/javascript"> window.onload=function(){ var odiv=document.getElementById("div1"); odiv.onmouseover=function(){ startMove(this,{width:400})? ? ? ? ? ? ? ? ? } odiv.onmouseout=function(){ startMove(this,{width:200})? ? ? ? ? ? ? ? ? } } function getStyle(obj,name){ if(obj.currentStyle){ return obj.currentStyle[name]; } else{ return getComputedStyle(obj,false)[name]; } } function startMove(obj,json,fnend){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var Bstop=true; for (var attr in json) { if(attr=="opacity"){ cur=Math.round(parseFloat(getStyle(obj,attr))*100) } else{ cur=parseInt(getStyle(obj,attr)) } } var speed=(json[attr]-cur)/6; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(cur!=json[attr]) Bstop=false; if(attr=="opacity"){ obj.style.filter="alpha(opacity"+(speed+cur)+")"; obj.style.opacity=(speed+cur)/100 } else{ obj.style[attr]=speed+cur+"px" } if(Bstop){ clearInterval(obj.timer) if(fnend)fnend(); } }) } </script> </head> <body> <div id="div1"> </div> </body></html>
查看完整描述

1 回答

?
stone310

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

首先明白Bstop的作用,是為了檢測最后所有屬性的值是否達(dá)到目標(biāo)值(即動(dòng)畫是否全部完成),是怎么檢測的呢,分三步
第一步,startMove這個(gè)函數(shù)是通過計(jì)時(shí)器不斷調(diào)用來完成動(dòng)畫效果,那么它每次調(diào)用的時(shí)候Bstop都賦值為true(var Bstop=true)
第二步,if(cur!=json[attr])Bstop=false;是用來判斷當(dāng)前元素的屬性值是否不等于你設(shè)定的目標(biāo)值(即動(dòng)畫是否還有沒完成的),如果不等于,那么Bstop就是false,這里if后面沒有{},說明如果條件成立,只執(zhí)行第一條語句,即Bstop=false;
第三步,最后那里有個(gè)if(Bstop){},相當(dāng)于if(Bstop==true)就停止計(jì)時(shí)器,

現(xiàn)在可以發(fā)現(xiàn),如果第二步有動(dòng)畫沒完成,那么Bstop是false,則第三步不成立,計(jì)時(shí)器不會(huì)停止,然后計(jì)時(shí)器繼續(xù)調(diào)用第一步,Bstop又變成true(第一步),然后繼續(xù)第二步,第三步,直到所有動(dòng)畫完成,到了第三步Bstop還是true,那么就執(zhí)行第三步的停止計(jì)時(shí)器

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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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