|
1 |
| -# lottie-vue |
2 |
| -Lottie player wrapper for Vue.js |
| 1 | +## LottiePlayer Vue Component |
3 | 2 |
|
4 |
| -`cd example && yarn serve` |
| 3 | +This is a Vue component for the Lottie Web Player |
| 4 | + |
| 5 | +## Documentation |
| 6 | + |
| 7 | +- [View documentation](https://github.com/LottieFiles/lottie-vue) |
| 8 | + |
| 9 | +#### In Javascript or TypeScript: |
| 10 | + |
| 11 | +1. Install package using npm or yarn. |
| 12 | + |
| 13 | +```shell |
| 14 | +npm install --save @lottiefiles/vue-lottie-player |
| 15 | +``` |
| 16 | + |
| 17 | +2. Import package in your code. |
| 18 | + |
| 19 | +```javascript |
| 20 | +import LottieVuePlayer from "@lottiefiles/vue-lottie-player"; |
| 21 | +``` |
| 22 | + |
| 23 | +3. Add the player as a plugin to Vue |
| 24 | +``` javascript |
| 25 | +Vue.use(LottieVuePlayer); |
| 26 | +``` |
| 27 | + |
| 28 | +## Example/Development |
| 29 | + |
| 30 | +1. Clone repo |
| 31 | + |
| 32 | +2. run yarn install |
| 33 | + |
| 34 | +## Usage |
| 35 | + |
| 36 | +### Player component |
| 37 | + |
| 38 | +Add the element `lottie-vue-player` and set the `src` prop to a URL pointing to a valid Lottie JSON. Full example of an App.vue file is shown below. |
| 39 | + |
| 40 | +```vue |
| 41 | +<template> |
| 42 | + <div id="app"> |
| 43 | + <lottie-vue-player :src="`https://assets10.lottiefiles.com/packages/lf20_tzjfwgud.json`" |
| 44 | + :theme="options.theme" |
| 45 | + :player-size="options.playerSize" |
| 46 | + :player-controls="true" |
| 47 | + style="width: 100%; height:400px"> |
| 48 | + </lottie-vue-player> |
| 49 | + </div> |
| 50 | +</template> |
| 51 | +
|
| 52 | +<script> |
| 53 | +
|
| 54 | + export default { |
| 55 | + name: 'App', |
| 56 | + data() { |
| 57 | + return { |
| 58 | + options: { |
| 59 | + minimizable: false, |
| 60 | + playerSize: "standard", |
| 61 | + backgroundColor: '#fff', |
| 62 | + backgroundStyle: 'color', |
| 63 | + theme: { |
| 64 | + controlsView: "standard", |
| 65 | + active: "light", |
| 66 | + light: { |
| 67 | + color: '#3D4852', |
| 68 | + backgroundColor: '#fff', |
| 69 | + opacity: '0.7', |
| 70 | + }, |
| 71 | + dark: { |
| 72 | + color: '#fff', |
| 73 | + backgroundColor: '#202020', |
| 74 | + opacity: '0.7', |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + } |
| 81 | +</script> |
| 82 | +
|
| 83 | +``` |
| 84 | + |
| 85 | +## Props |
| 86 | + |
| 87 | +| Prop | Description | Type | Default | |
| 88 | +| -------------------- | ---------------------------------------------------------------------- | ------------------ | ----------- | |
| 89 | +| `autoplay` | Autoplay animation on load. | `boolean` | `false` | |
| 90 | +| `backgroundColor` | Background color. | `string` | `undefined` | |
| 91 | +| `playerControls` | Show controls. | `boolean` | `false` | |
| 92 | +| `showColorPicker` | Show color picker | `boolean` | `false` | |
| 93 | +| `playerSize` | Player set size (hide, minimal, standard) | `string` | `standard` | |
| 94 | +| `loop` | Whether to loop animation. | `boolean` | `false` | |
| 95 | +| `speed` | Animation speed. | `number` | `1` | |
| 96 | +| `style` | The style for the container. | `object` | `undefined` | |
| 97 | +| `src` _(required)_ | Bodymovin JSON data or URL to JSON. | `object` | `string`| `undefined` | |
| 98 | +| `is_dotlottie` | Swap out normal player for dotlottie player | `boolean` | `false` | |
| 99 | +## Events |
| 100 | + |
| 101 | +The following events are exposed and can be listened to via `addEventListener` calls. |
| 102 | + |
| 103 | +| Name | Description | |
| 104 | +| ---------- | ------------------------------------------------------------------------- | |
| 105 | +| `load` | Animation data is loaded. | |
| 106 | +| `error` | An animation source cannot be parsed, fails to load or has format errors. | |
| 107 | +| `ready` | Animation data is loaded and player is ready. | |
| 108 | +| `play` | Animation starts playing. | |
| 109 | +| `pause` | Animation is paused. | |
| 110 | +| `stop` | Animation is stopped. | |
| 111 | +| `freeze` | Animation is paused due to player being invisible. | |
| 112 | +| `loop` | An animation loop is completed. | |
| 113 | +| `complete` | Animation is complete (all loops completed). | |
| 114 | +| `frame` | A new frame is entered. | |
| 115 | + |
| 116 | +## Methods |
| 117 | + |
| 118 | +### `togglePlayPause() => void` |
| 119 | + |
| 120 | +Toggle animation play pause. |
| 121 | + |
| 122 | +#### Returns |
| 123 | + |
| 124 | +Type: `void` |
| 125 | + |
| 126 | +### `toggleFullscreen() => void` |
| 127 | + |
| 128 | +Toggle full screen player. |
| 129 | + |
| 130 | +#### Returns |
| 131 | + |
| 132 | +Type: `void` |
| 133 | +### `toggleLoop() => void` |
| 134 | + |
| 135 | +Toggle animation loop. |
| 136 | + |
| 137 | +#### Returns |
| 138 | + |
| 139 | +Type: `void` |
| 140 | + |
| 141 | +### `setPlayerSpeed(speed?: number) => void` |
| 142 | + |
| 143 | +Sets animation play speed. |
| 144 | + |
| 145 | +#### Parameters |
| 146 | + |
| 147 | +| Name | Type | Description | |
| 148 | +| ------- | -------- | --------------- | |
| 149 | +| `value` | `number` | Playback speed. | |
| 150 | + |
| 151 | +#### Returns |
| 152 | + |
| 153 | +Type: `void` |
| 154 | + |
| 155 | +### `stop() => void` |
| 156 | + |
| 157 | +Stops animation play. |
| 158 | + |
| 159 | +#### Returns |
| 160 | + |
| 161 | +Type: `void` |
| 162 | + |
| 163 | +### `setBackgroundColor(color: string) => void` |
| 164 | + |
| 165 | +set background color. |
| 166 | + |
| 167 | +#### Returns |
| 168 | + |
| 169 | +Type: `void` |
| 170 | +## License |
| 171 | + |
| 172 | +MIT License © LottieFiles.com |
0 commit comments