Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增destroy方法,页面销毁时调用destroy可避免动画二次渲染时失效的问题 #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {setup, g} from './adapter'
const {window, document, navigator} = g
import { setup, g } from './adapter'
const { window, document, navigator } = g

;'__LOTTIE_CANVAS__'
; '__LOTTIE_CANVAS__'

function loadAnimation(options) {
function loadAnimation (options) {
['wrapper', 'container'].forEach(key => {
if (key in options) {
throw new Error(`Not support '${key}' parameter in miniprogram version of lottie.`)
Expand All @@ -20,11 +20,25 @@ function loadAnimation(options) {
return window.lottie.loadAnimation(options)
}

const {freeze, unfreeze} = window.lottie
const miniprogramDestroy = window.lottie.destroy

const { freeze, unfreeze, getRegisteredAnimations } = window.lottie

function destroy (name) {
const animations = getRegisteredAnimations() || []
animations.forEach(animation => {
animation.wrapper = {
innerHTML: ''
}
})
miniprogramDestroy(name)
}


export {
setup,
loadAnimation,
freeze,
unfreeze,
destroy
}