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

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

關(guān)于animate的rate和speed理解

?我的理解是time是總的時(shí)間,分成很多段,rate是每段的時(shí)間,每個(gè)rate就移動(dòng)speed的位移,

let?animate?=?setInterval(()?=>?{

????????????if?(?this.picBox.style.left?==?goal?||?Math.abs(Math.abs(parseFloat(this.picBox.style.left))?-?Math.abs(goal))?<?Math.abs(speed)?)?{

????????????????this.picBox.style.left?=?goal?+?"px"

????????????????clearInterval(animate)

???????????????


????????????}?else?{

????????????????this.picBox.style.left?=?parseFloat(this.picBox.style.left)?-?speed?+?"px"

????????????}

????????},?rate)

? ? ? ??


正在回答

1 回答

animate(offset)?{????????//?定義切換時(shí)間為1000毫秒?1秒????????const?time?=?1000????????????//稍微移動(dòng)為0.1秒????????const?rate?=?100????????????//計(jì)算移動(dòng)距離????????let?speed?=?offset?/?(time?/?rate)????????????//?計(jì)算目標(biāo)位置使用parseFloat去掉單位????????let?goal?=?parseFloat(this.picBox.style.left)?-?offset????????this.animated?=?true????????//判斷是否到達(dá)目標(biāo)位置????????let?animate?=?setInterval(()?=>?{?//計(jì)算去掉單位的目標(biāo)絕對值減去目標(biāo)位置的絕對值小于移動(dòng)距離的絕對值????????????if?(this.picBox.style.left?==?goal?||?Math.abs(Math.abs(parseFloat(this.picBox.style.left))?-?Math.abs(goal))?<?Math.abs(speed))?{????????????????this.picBox.style.left?==?goal????????????????clearInterval(animate)????????????????this.animated?=?false????????????????if?(parseFloat(this.picBox.style.left)?==?0)?{????????????????????this.picBox.style.left?=?-this.sliders?*?this.sliderWidth?+?"px"????????????????}?else?if?(parseFloat(this.picBox.style.left)?==?-(this.sliders?+?1)?*?this.sliderWidth)?{????????????????????this.picBox.style.left?=?-this.sliderWidth?+?"px"????????????????}????????????}?else?{????????????????//未到達(dá)目標(biāo)位置繼續(xù)移動(dòng)????????????????this.picBox.style.left?=?parseFloat(this.picBox.style.left)?-?speed?+?"px"????????????}????????},?rate)????}

我的理解在注釋里和你的基本一致

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

關(guān)于animate的rate和speed理解

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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