提交 f4879463 编写于 作者: DCloud_JSON's avatar DCloud_JSON

更新 示例项目 drop-card 简化移动卡片位置(帧动画)的函数逻辑

上级 9c1b991c
...@@ -128,36 +128,29 @@ ...@@ -128,36 +128,29 @@
k = -1 k = -1
} }
function cardTo(x:number,y:number,callback: () => void,s:number = 10){ function cardTo(x:number,y:number,callback: () => void,speed:number = 10){
// console.log('s',s);
// console.log('--cardTo---',x,y);
let interval:number = 0 let interval:number = 0
let _k:number = 1 let acceleration:number = 1
interval = setInterval(()=>{ interval = setInterval(()=>{
// 加速度 // 加速度
_k += 0.2 acceleration += 0.2
const dx = x - this.x const dx = x - this.x
if(this.x.toInt() != x){ if(Math.abs(dx) < 1){
this.x += dx/s*_k
// console.log('dx/s*_k',dx/s*_k)
if(Math.abs(dx) < 3){
this.x = x this.x = x
}else{
this.x += dx/speed*acceleration
} }
}
const dy = y - this.y const dy = y - this.y
if(this.y.toInt() != y){ if(Math.abs(dy) < 1){
this.y += dy/s*_k
// console.log('dy/s*_k',dy/s*_k)
if(Math.abs(dy) < 3){
this.y = y this.y = y
}else{
this.y += dy/speed*acceleration
} }
}
// console.log('this.x',this.x,'this.y',this.y);
// console.log('x',x,'y',y);
this.moveCard() this.moveCard()
if( this.x.toInt() == x.toInt() && this.y.toInt() == y.toInt()){ if( this.x == x && this.y == y){
clearInterval(interval) clearInterval(interval)
callback() callback()
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册