// 使用 wx.createAnimation API 示例 const animation = wx.createAnimation({ duration: 300, timingFunction: 'ease-out' }) animation.opacity(0).translateY(20).step() this.setData({ animationData: animation.export() })
/* 自定義導(dǎo)航切換動畫 */ .page-enter { transform: translateX(100%); } .page-enter-active { transition: transform 0.3s ease; }2. 加載狀態(tài)創(chuàng)意呈現(xiàn)
// 點(diǎn)擊波紋效果 handleTap(e) { const { x, y } = e.detail this.setData({ rippleX: x, rippleY: y }) setTimeout(() => this.setData({ rippleX: null }), 600) }
三、 性能優(yōu)化關(guān)鍵指標(biāo)
優(yōu)化方向
具體措施
預(yù)期效果
圖片資源
使用SVG代替PNG動畫
體積減少70%+
渲染層級
控制`z-index`,減少重疊區(qū)域重繪
渲染耗時降低40%
動畫銷毀
頁面隱藏時停止后臺動畫
內(nèi)存占用下降30%
幀率監(jiān)控
使用性能面板監(jiān)測FPS
確?!?0幀流暢體驗(yàn)
onTouchMove(e) { const deltaY = e.touches[0].clientY - this.startY this.animation.translateY(deltaY).step() this.setData({ dragAnimation: this.animation.export() }) }
.card { transform: perspective(800px) rotateY(15deg); transition: transform 0.4s; }