From 4088572f3e2b4d682fbf88259ac8f6ba84555574 Mon Sep 17 00:00:00 2001 From: linju Date: Tue, 29 Aug 2023 15:43:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=20drop-card=20=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=EF=BC=9A=E5=BD=93=E5=8D=A1=E7=89=87=E5=9C=A8x=E8=BD=B4?= =?UTF-8?q?=E6=96=B9=E5=90=91=E4=B8=8A=E8=A2=AB=E6=8B=96=E5=8A=A8=E4=B8=80?= =?UTF-8?q?=E6=AE=B5=E8=BE=83=E7=9F=AD=E7=9A=84=E8=B7=9D=E7=A6=BB=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=9D=BE=E5=BC=80=E5=90=8E=EF=BC=8C=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E4=BC=9A=E8=BF=94=E5=9B=9E=E4=B8=AD=E5=BF=83=E7=9A=84=E5=8A=A8?= =?UTF-8?q?=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/template/drop-card/card/card.uvue | 86 +++++++++++++++++-------- 1 file changed, 58 insertions(+), 28 deletions(-) diff --git a/pages/template/drop-card/card/card.uvue b/pages/template/drop-card/card/card.uvue index a8a48459..e66d9caf 100644 --- a/pages/template/drop-card/card/card.uvue +++ b/pages/template/drop-card/card/card.uvue @@ -128,39 +128,69 @@ k = -1 } - if(k !== 0.0){ - let interval:number = 0; + function cardTo(x:number,y:number,callback: () => void,s:number = 10){ + // console.log('s',s); + // console.log('--cardTo---',x,y); + let interval:number = 0 + let _k:number = 1 interval = setInterval(()=>{ - this.x += k * 30 - this.y *= 1.1 + // 加速度 + _k += 0.2 + + const dx = x - this.x + if(this.x.toInt() != x){ + this.x += dx/s*_k + // console.log('dx/s*_k',dx/s*_k) + if(Math.abs(dx) < 3){ + this.x = x + } + } + const dy = y - this.y + if(this.y.toInt() != y){ + this.y += dy/s*_k + // console.log('dy/s*_k',dy/s*_k) + if(Math.abs(dy) < 3){ + this.y = y + } + } + // console.log('this.x',this.x,'this.y',this.y); + // console.log('x',x,'y',y); + this.moveCard() - if( Math.abs(this.x) > Math.abs(k * screenWidth * 1.5)){ + if( this.x.toInt() == x.toInt() && this.y.toInt() == y.toInt()){ clearInterval(interval) - // 飘动的卡片挪回中心 - - // 状态图标变回透明 - this.setINodeStyle("state-icon-like",'opacity', 0) - this.setINodeStyle("state-icon-dislike",'opacity', 0) - - // 设置为透明,防止飘回时因为 margin-top 太高,露出来 - this.setINodeStyle("card",'opacity', 0) - setTimeout(()=>{ - this.setINodeStyle("card",'opacity', 1) - },300) - - // 执行卡片飘动后事件,注意uni.$emit是全局事件。其他卡片也会执行 - uni.$emit('uni-drop-card-float',null) - floating = false - } + callback() + } },16) - }else{ - // 坐标归零 - this.x = 0 - this.y = 0 - this.moveCard() - floating = false } - }, + + if(k.toInt() != 0){ + cardTo(k * screenWidth * 1.3, this.y * 3,()=>{ + // 状态图标变回透明 + this.setINodeStyle("state-icon-like",'opacity', 0) + this.setINodeStyle("state-icon-dislike",'opacity', 0) + + // 设置为透明,防止飘回时因为 margin-top 太高,露出来 + this.setINodeStyle("card",'opacity', 0) + setTimeout(()=>{ + this.setINodeStyle("card",'opacity', 1) + },300) + + // 执行卡片飘动后事件,注意uni.$emit是全局事件。其他卡片也会执行 + uni.$emit('uni-drop-card-float',null) + floating = false + },8) + }else{ + const _x:number = this.x + const _y:number = this.y + cardTo( (_x*-0.05).toInt() , (_y*-0.05).toInt() ,()=>{ + cardTo(0,0,()=>{ + console.log('bounce') + floating = false + },30) + }) + } + }, moveCard() { this.setINodeStyle("card", 'transform', -- GitLab