關于animate的rate和speed理解
?我的理解是time是總的時間,分成很多段,rate是每段的時間,每個rate就移動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)
? ? ? ??
2021-05-18
我的理解在注釋里和你的基本一致