juliangarnier / anime

JavaScript animation engine
https://animejs.com
MIT License
50.46k stars 3.68k forks source link

feat: add support for timeline markers #809

Closed diegolealco closed 2 years ago

diegolealco commented 2 years ago

You can find example code testing this functionality here: https://github.com/diegolealco/anime-test/blob/main/index.jsx

The reason for adding this feature is to enable me to create complex animations involving multiple components, whose animations would be added asynchronously or when I cannot ensure animations are added in the correct order. I could rely on using absolute offsets everywhere, however, this change enable me/you to also create markers relative to other markers and animation offsets relative to markers through a third optional parameter to timeline.add().

    anime
      .timeline()
      .addMarker({ name: "one", offset: 2000 }) // absolute marker
      .addMarker({ name: "two", offset: "-=1000", referenceMarker: "one" }) // marker relative to another marker
      .add( { targets: element, keyframes: [{ translateX: "500px", duration: 1000 }], }, null, "one" ) // use marker
      .add( { targets: element2, keyframes: [{ translateX: "250px", duration: 1000 }], }, "+=2000", "two" ) // offset relative to a marker
diegolealco commented 2 years ago

Given the inactivity, I decided to set up a separate fork as I need these changes with a little bit of urgency.

I would be happy to backport any changes upstream, even to the newly version that is being worked on right now - just give me a shout; I would love to contribute.

PS the original diff was quite small. The fork looks like it diverged a bit mostly because of the formatting and code removal.

juliangarnier commented 2 years ago

I would be happy to backport any changes upstream, even to the newly version that is being worked on right now - just give me a shout; I would love to contribute.

Timeline markers is a feature planned for 3.3 so that would be great! I'm in the process of refactoring a big part of the code base in the v3.3.0 branch. So all next PRs should be based on this branch since a lot have changed in terms of code structure.