小程序ビジネスでは、UI の同僚から提供された JSON ファイルを頻繁に使用し、Lottie を使ってアニメーションを作成する際に、2 つの問題に直面しました:
- アニメーションにギザギザがあり、鮮明でない
- Windows 上でエラーが発生します、
TypeError: Cannot read properties of undefined (reading 'requestAnimationFrame')
解決策:
- 鮮明でない
const canvas = res.node;
const context = canvas.getContext('2d');
const { pixelRatio: dpr = 2 } = systemInfo.value;
// 56: 画像の元のサイズ
canvas.width = 56 * dpr;
canvas.height = 56 * dpr;
context.scale(dpr, dpr);
lottie.setup(canvas);
- ウィンドウのバグ
const myAnim = lottie.loadAnimation({});
// アンロードまたは使用しない場合は一時停止する必要があります
onUnload(() => {
myAnim?.pause();
});
この記事は Mix Space によって xLog に同期更新されました
元のリンクは https://looyank.cc/posts/shit/lottie