ホームページ >ウェブフロントエンド >uni-app >Uni-AppのアニメーションAPIを使用するにはどうすればよいですか?
Uni-AppのアニメーションAPIを使用するには、次の手順に従う必要があります。
アニメーションインスタンスの作成: uni.createAnimation(options)
を使用してアニメーションインスタンスを作成することから始めます。 options
パラメーターを使用すると、期間、タイミング機能、遅延などのデフォルトのプロパティを設定できます。
<code class="javascript">const animation = uni.createAnimation({ duration: 1000, timingFunction: 'ease', });</code>
アニメーションアクションの定義:アニメーションインスタンスが提供するメソッドを使用して、実行するアクションを定義します。一般的な方法にはtranslate()
、 rotate()
、 scale()
、およびopacity()
が含まれます。これらのアクションは、アニメーションインスタンスのプロパティを変更します。
<code class="javascript">animation.translate(30, 30).rotate(45).scale(2, 2).step();</code>
アニメーションデータのエクスポート:アクションを定義した後、ビューで使用するアニメーションデータをエクスポートする必要があります。アニメーションインスタンスのexport()
メソッドを呼び出すことにより、アニメーションデータをエクスポートできます。
<code class="javascript">this.animationData = animation.export();</code>
アニメーションをビューに適用します。最後に、ビューのスタイルでanimation
プロパティを使用して、エクスポートしたアニメーションデータをビューに適用します。
<code class="html"><view :animation="animationData">Animated View</view></code>
Uni-AppのアニメーションAPIの重要な機能には次のものがあります。
options
オブジェクトには、 duration
、 timingFunction
、 delay
、 transformOrigin
などのプロパティを含めることができます。x
とy
値で要素を移動します。sx
値は要素を水平方向にスケーリングし、オプションのsy
値は垂直にスケーリングします。 sy
が提供されていない場合、デフォルトはsx
値になります。value
は0〜1の数です。options
パラメーターは、アニメーションのデフォルトプロパティをオーバーライドできます。はい、 step()
メソッドを使用してUNI-APPで複数のアニメーションを組み合わせることができます。この方法を使用すると、アニメーションをさまざまなステップにセグメント化できます。それぞれが独自のプロパティとタイミングを備えています。
複数のアニメーションを組み合わせる方法の例は次のとおりです。
<code class="javascript">const animation = uni.createAnimation(); animation.translate(30, 30).step({ duration: 300 }); animation.rotate(45).step({ duration: 300 }); animation.scale(2, 2).step({ duration: 300 }); this.animationData = animation.export();</code>
この例では、要素は最初に30ピクセルを右に移動し、300ミリ秒を超える30ピクセルを下に移動し、次に次の300ミリ秒で45度を回転させ、最終的にさらに300ミリ秒にわたってそのサイズの2倍にスケーリングします。
UNI-APPのアニメーションのタイミングを制御するには、次の方法とプロパティを使用できます。
持続時間:アニメーションインスタンスを作成するときにduration
プロパティを設定するか、 step()
メソッド内でアニメーションの各セグメントが続く時間を制御します。
<code class="javascript">const animation = uni.createAnimation({ duration: 1000, // Default duration for all steps }); animation.translate(30, 30).step({ duration: 500 }); // Override duration for this step</code>
タイミング関数: timingFunction
プロパティを使用して、アニメーションの速度曲線を制御します。オプションには、 linear
、 ease
、 ease-in
、 ease-out
、およびease-in-out
含まれます。
<code class="javascript">const animation = uni.createAnimation({ timingFunction: 'ease-in-out', });</code>
遅延: delay
プロパティを使用して、アニメーションが開始される前に遅延を追加します。
<code class="javascript">const animation = uni.createAnimation({ delay: 500, // Delay the start of the animation by 500ms });</code>
ステップ: step()
メソッドを使用して、アニメーションを異なるステップに分割します。それぞれに独自のタイミングプロパティがあります。
<code class="javascript">animation.translate(30, 30).step({ duration: 300, timingFunction: 'ease-in' }); animation.rotate(45).step({ duration: 300, timingFunction: 'ease-out' });</code>
これらのプロパティを慎重に設定することにより、UNI-APPのアニメーションのタイミングとフローを正確に制御できます。
以上がUni-AppのアニメーションAPIを使用するにはどうすればよいですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。