Animation
We have built-in animation types that can be executed on elements by calling the player instance method playAnimationByElementKey
.
How to Use
After getting the player instance through ref
or onReady
, call the playAnimationByElementKey
method with the element's key
and animation parameters to execute the animation. Use the cancelAnimation
method to cancel the currently playing animation.
import {
AnimationType,
MouseEventParams,
ICraftPlayer,
ICraftPlayerInstance,
} from "@icraft/player-react";
import React from "react";
const style = {
width: "100%",
height: "100%",
position: "relative" as const,
overflow: "hidden" as const,
};
export default () => {
const playerRef = React.useRef<ICraftPlayerInstance>();
const onClick = (e: MouseEventParams) => {
const player = playerRef.current;
const { instance: Element } = e;
if (!Element) {
player?.cancelAnimation();
return;
}
if (Element.typeName !== "line") {
player?.playAnimationByElementKey(Element.key, {
animationDuration: 3,
animationType: AnimationType.HeartBeat,
animationShowTip: true,
});
} else {
player?.playAnimationByElementKey(Element.key, {
animationDuration: 3,
animationType: AnimationType.LoopFlow,
});
}
};
const onReady = (player: ICraftPlayerInstance) => {
const user = player.getElementsByName("User")?.[0];
if (user) {
player.playAnimationByElementKey(user.key, {
animationDuration: 100,
animationType: AnimationType.Rotate,
});
}
};
return (
<div style={style}>
<ICraftPlayer
src='/templates/AWSCloud.iplayer'
onClick={onClick}
onReady={onReady}
ref={playerRef}
/>
</div>
);
};
API
Functions
Name | Description | Type |
---|---|---|
getElementsByName | Get multiple elements by name | (name: string) => Element3D[] |
playAnimationByElementKey | Execute built-in animation on element | (elementKey: string,animationOptions: AnimationActionOptions) => void |
cancelAnimation | Cancel all animations | () => void |
AnimationActionOptions
Name | Description | Type | Default | Required |
---|---|---|---|---|
animationType | Animation type | AnimationType | AnimationType.FadeIn | true |
animationDuration | Animation duration (sec) | number | 2 | true |
animationDelay | Animation delay (sec) | number | 0 | false |
animationShowTip | Show dynamic tip | boolean | true | false |
tipContent | Narration text | string | name | false |
tipBackground | Narration text color | string | white | false |
flowLineColor | Flow line color | string | blue | false |
flowLineThinness | Flow line thinness factor (controls middle section contraction, higher value means more prominent middle section) | number | 0.5 | false |
flowLineSize | Flow line size factor (controls overall line thickness) | number | 0.12 | false |
AnimationType
Name | Description |
---|---|
FadeIn | Fade in (non-line elements only) |
FadeOut | Fade out (non-line elements only) |
UpAndDown | Float up/down (non-line elements only) |
HeartBeat | Heartbeat (non-line elements only) |
ColorChange | Color change (non-line elements only) |
Bounce | Bounce (non-line elements only) |
Rotate | Rotate (non-line elements only) |
EnterSubScene | Enter sub-scene (non-line elements only) |
ExitSubScene | Exit sub-scene (non-line elements only) |
Draw | Draw animation (line elements only) |
Flow | Flow animation (line elements only) |
LoopFlow | Loop flow (line elements only) |