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

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

上级 9c1b991c
...@@ -56,19 +56,19 @@ ...@@ -56,19 +56,19 @@
screenHeight = e.screenHeight; screenHeight = e.screenHeight;
} }
}) })
// TODO 需要延迟设置才能生效 // TODO 需要延迟设置才能生效
setTimeout(()=>{ setTimeout(()=>{
this.setINodeStyle('card','height', screenHeight * 0.7 + 'px'); this.setINodeStyle('card','height', screenHeight * 0.7 + 'px');
this.setINodeStyle('card-img','height', screenHeight * 0.7 + 'px'); this.setINodeStyle('card-img','height', screenHeight * 0.7 + 'px');
this.initCardStyle() this.initCardStyle()
},200) },200)
uni.$on('uni-drop-card-float',()=>{ uni.$on('uni-drop-card-float',()=>{
this.floatCount ++ this.floatCount ++
this.initCardStyle() this.initCardStyle()
}) })
}, },
methods: { methods: {
initCardStyle(){ initCardStyle(){
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
return // 浮动动画进行中 return // 浮动动画进行中
} }
floating = true floating = true
// 设置释放之后飘走的方向 0回到坐标中心 1向右 2向左 // 设置释放之后飘走的方向 0回到坐标中心 1向右 2向左
let k:number = 0; let k:number = 0;
if (this.x > screenWidth / 10 ) { if (this.x > screenWidth / 10 ) {
...@@ -127,60 +127,53 @@ ...@@ -127,60 +127,53 @@
}else if(this.x < screenWidth * -1 / 10){ }else if(this.x < screenWidth * -1 / 10){
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 this.x = x
// console.log('dx/s*_k',dx/s*_k) }else{
if(Math.abs(dx) < 3){ this.x += dx/speed*acceleration
this.x = x
}
} }
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 this.y = y
// console.log('dy/s*_k',dy/s*_k) }else{
if(Math.abs(dy) < 3){ this.y += dy/speed*acceleration
this.y = y
}
} }
// 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()
} }
},16) },16)
} }
if(k.toInt() != 0){ if(k.toInt() != 0){
cardTo(k * screenWidth * 1.3, this.y * 3,()=>{ cardTo(k * screenWidth * 1.3, this.y * 3,()=>{
// 状态图标变回透明 // 状态图标变回透明
this.setINodeStyle("state-icon-like",'opacity', 0) this.setINodeStyle("state-icon-like",'opacity', 0)
this.setINodeStyle("state-icon-dislike",'opacity', 0) this.setINodeStyle("state-icon-dislike",'opacity', 0)
// 设置为透明,防止飘回时因为 margin-top 太高,露出来 // 设置为透明,防止飘回时因为 margin-top 太高,露出来
this.setINodeStyle("card",'opacity', 0) this.setINodeStyle("card",'opacity', 0)
setTimeout(()=>{ setTimeout(()=>{
this.setINodeStyle("card",'opacity', 1) this.setINodeStyle("card",'opacity', 1)
},300) },300)
// 执行卡片飘动后事件,注意uni.$emit是全局事件。其他卡片也会执行 // 执行卡片飘动后事件,注意uni.$emit是全局事件。其他卡片也会执行
uni.$emit('uni-drop-card-float',null) uni.$emit('uni-drop-card-float',null)
floating = false floating = false
},8) },8)
}else{ }else{
const _x:number = this.x const _x:number = this.x
const _y:number = this.y const _y:number = this.y
cardTo( (_x*-0.05).toInt() , (_y*-0.05).toInt() ,()=>{ cardTo( (_x*-0.05).toInt() , (_y*-0.05).toInt() ,()=>{
...@@ -246,4 +239,4 @@ ...@@ -246,4 +239,4 @@
box-shadow: 0 0 1px #EBEBEB; box-shadow: 0 0 1px #EBEBEB;
opacity: 0; opacity: 0;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册