Rich-Harris / ramjet

Morph DOM elements from one state to another with smooth animations and transitions
http://www.rich-harris.co.uk/ramjet/
MIT License
5.45k stars 158 forks source link

Web Animations API #36

Open Martin-Pitt opened 9 years ago

Martin-Pitt commented 9 years ago

Hi @Rich-Harris,

Would it be possible to create a ramjet that can rely entirely on the web animations api? It would be great to be able to make ramjets of different elements and composite them into one big animation, e.g:

var anim = new AnimationSequence([
  ramjet.transform(document.querySelector('button.nav.active'), document.querySelector('header.page')),
  new Animation(document.querySelector('img.avatar'), [ { transform: 'translateX(300px) rotate(30deg) translateX(-400px) } ])
], { duration: 500, fill: 'forwards' });

var player = document.timeline.play(anim);
player.play();

The Web Animations API polyfill is used by Polymer for example and works really well, providing cross-browser support. https://github.com/web-animations/web-animations-js

Rich-Harris commented 9 years ago

I did wonder about using web animations under the hood. As an internal implementation detail, it didn't really make sense as there are no performance benefits over CSS animations (as far as I can see), while the polyfill introduces a severe penalty because the animations are timer-based IIRC and have to run on the main thread.

But you make an interesting case about composition. I was planning to (eventually) make ramjet.transform return an object with things like pause and reverse methods - perhaps it would make more sense if that object was compatible with the web animations API. Definitely worth looking into for a future release