日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

android 购物车抛物线,添加到购物车抛物线动画

發布時間:2024/9/15 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 购物车抛物线,添加到购物车抛物线动画 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我感覺嚴格的拋物線動畫不能通過createAnimation實現,但是可以通過幀動畫。

這是我之前寫的拋物線組件:

ts:

Component({

data: {

left: 0,

top: 0,

hidden: true,

},

timer: 0,

detached() {

this.cancel();

},

pageLifetimes: {

hide() {

this.cancel();

},

},

methods: {

animate(options: IOptions & { onEnd: () => void }) {

const { onEnd } = options;

this.cancel(false);

this.setData({

left: options.start.x,

top: options.start.y,

hidden: false,

});

parabolaAnimate(options, ({ x, y }, timer) => {

this.setData({ left: x, top: y });

this.timer = timer;

if (timer === 0) {

this.setData({ hidden: true });

if (typeof onEnd === 'function') {

onEnd();

}

}

});

},

cancel(hidden = true) {

if (this.timer) {

clearInterval(this.timer);

this.timer = 0;

}

if (hidden) {

this.setData({ hidden: true });

}

},

},

});

interface IOptions {

start: { x: number; y: number };

end: { x: number; y: number };

topY: number;

gforce?: number;

frameDuration?: number;

}

function parabolaAnimate(

options: IOptions,

callback: (ponit: { x: number; y: number }, timer: number) => void

) {

const { start, end, topY, gforce = 2000, frameDuration = 10 } = options;

const tStartToTop = Math.sqrt((Math.abs(topY - start.y) * 2) / gforce);

const tTopToEnd = Math.sqrt((Math.abs(topY - end.y) * 2) / gforce);

const tFrame = frameDuration / 1000;

let tRest = tStartToTop + tTopToEnd;

let vx = (end.x - start.x) / (tStartToTop + tTopToEnd);

let vy = -gforce * tStartToTop;

let startX = start.x;

let startY = start.y;

let timer = setInterval(() => {

const ponit = {

x: startX + vx * tFrame,

y: startY + vy * tFrame + (gforce * tFrame * tFrame) / 2,

};

vy = vy + gforce * tFrame;

tRest = tRest - tFrame;

startX = ponit.x;

startY = ponit.y;

if (tRest <= 0) {

clearInterval(timer);

timer = 0;

}

callback(ponit, timer);

}, frameDuration);

}

wxml:

調用:

Page({

onReady() {

this.parabolaBall = this.selectComponent("#parabola-ball");

this.systemInfo = wx.getSystemInfoSync();

},

animateBall(e) {

const { screenHeight, screenWidth } = this.systemInfo;

const { clientX, clientY } = e.touches[0];

const start = {

x: clientX,

y: clientY

};

this.parabolaBall.animate({

start,

end: {

x: screenWidth * 0.62,

y: screenHeight + 30

},

topY: clientY + 50

});

}

});

備注:重點在于拋物線函數parabolaAnimate的算法,其中起點坐標,終點坐標,頂點y坐標,重力加速度值是決定拋物線軌跡的必須要素。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的android 购物车抛物线,添加到购物车抛物线动画的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。