最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the difference between Lottie Events and Lottie EventListeners and How to use? - Stack Overflow

programmeradmin2浏览0评论

The documentation has both Events and EventListeners. I can get the EventListeners to fire but the Events do not have adequate documentation for me to get going. What is the difference and how do you use? Thank you.

Events (Do not work, how to use?)

// From the Documentation

  • onComplete
  • onLoopComplete
  • onEnterFrame
  • onSegmentStart

you can also use addEventListener with the following events:

  • plete
  • loopComplete
  • enterFrame
  • segmentStart
  • config_ready (when initial config is done)
  • data_ready (when all parts of the animation have been loaded)
  • data_failed (when part of the animation can not be loaded)
  • loaded_images (when all image loads have either succeeded or errored)
  • DOMLoaded (when elements have been added to the DOM)
  • destroy

// End Documentation

From the standard addEventListener usage, this works...

birbSequence.addEventListener('loopComplete', (e) => {
    console.log(e);
});

although 'plete' does not fire.

But to try out the stuff in Events like onEnterFrame?

var birbSequence = lottie.loadAnimation({
    container: bodyMovinContainer1,
    loop: true,
    renderer: 'svg',
    path: 'Birb Sequence 1.json',
    onEnterFrame: function(e) { console.log(e); }
});

I am really new to using Lottie though so could use some help.

Just want a way to see how to use Events

The documentation has both Events and EventListeners. I can get the EventListeners to fire but the Events do not have adequate documentation for me to get going. What is the difference and how do you use? Thank you.

https://github./airbnb/lottie-web#events

Events (Do not work, how to use?)

// From the Documentation

  • onComplete
  • onLoopComplete
  • onEnterFrame
  • onSegmentStart

you can also use addEventListener with the following events:

  • plete
  • loopComplete
  • enterFrame
  • segmentStart
  • config_ready (when initial config is done)
  • data_ready (when all parts of the animation have been loaded)
  • data_failed (when part of the animation can not be loaded)
  • loaded_images (when all image loads have either succeeded or errored)
  • DOMLoaded (when elements have been added to the DOM)
  • destroy

// End Documentation

From the standard addEventListener usage, this works...

birbSequence.addEventListener('loopComplete', (e) => {
    console.log(e);
});

although 'plete' does not fire.

But to try out the stuff in Events like onEnterFrame?

var birbSequence = lottie.loadAnimation({
    container: bodyMovinContainer1,
    loop: true,
    renderer: 'svg',
    path: 'Birb Sequence 1.json',
    onEnterFrame: function(e) { console.log(e); }
});

I am really new to using Lottie though so could use some help.

Just want a way to see how to use Events

Share Improve this question edited Apr 23, 2019 at 6:47 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 23, 2019 at 5:34 Ray VillarazaRay Villaraza 611 gold badge1 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Let's say we have our lottie animation:

const anim = lottie.loadAnimation({
  container: '#container',
  renderer: 'svg',
  loop: true,
  autoplay: true,
  ...
})

With Events:

anim.onComplete = function() {
  console.log('plete')
}
anim.onLoopComplete = function() {
  console.log('loopComplete')
}

With addEventListener:

anim.addEventListener('plete', function() {
  console.log('plete')
})
anim.addEventListener('loopComplete', function() {
  console.log('loopComplete')
})

You can use the addEventListener method to listen to all the events instead of the on* series of event hooks.

const options = {
  container: '#container',
  loop: false,
  autoplay: false,
  renderer: 'svg',
  rendererSettings: {
  scaleMode: 'noScale',
    clearCanvas: false,
    progressiveLoad: true,
    hideOnTransparent: true,
  },
};

try {
  const anim = lottie.loadAnimation({ ...options, path: 'URL_TO_JSON' });

  anim.addEventListener('plete', () => { console.log('plete'); });
  anim.addEventListener('loopComplete', () => { console.log('loopComplete'); });
  anim.addEventListener('data_ready ', () => { console.log('data_ready'); });
  anim.addEventListener('data_failed', () => { console.log('data_failed'); });
  anim.addEventListener('enterFrame', () => {
    console.log('enterFrame', anim.currentFrame);
  });
  // etc ...
} catch (error) 
  console.log('error loading anim');
}

Hope that helps!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论