Description
Given that the web animation API essentially provides a timeline and tween library built in to the browser. why limit it to only DOM elements?
A reason being for example if we want to animate properties that render on to canvas, like three.js
GSAP is often used with three.js to animate objects, which is done by mutating or calling the position properties of those objects.
An example from this pen
var geometry = new THREE.PlaneGeometry(4, 4);
var material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
});
var plane = new THREE.Mesh(geometry, material);
plane.position.set(3, 5, -0.4);
var tl = new TimelineMax({
repeat: -1
});
tl.to(plane.rotation, 2, {
z: -Math.PI,
ease: Power0.easeNone
});
scene.add(plane);
With the WEB API effectively a sort of a tween library built in, it reduces the need to load a library like GSAP if it's possible to do.
var tlEffect = new KeyframeEffect(plane, [{
rotation:-Math.PI
}], {
duration: 2000,
repeat: Infinity,
});
domcument.timeline.play(tlEffect)
scene.add(plane);
I understand it's out of scope of the specification since it's meant to allow an extension on what CSS already does.
But allowing objects can provide a wider adoption path, since it makes the API more extensible.
This matches a realistic workflow for large scale animations that use other renderers then the DOM.
Also it can generally be noted when an object is passed to the Keyframe object instead of a DOMNode, and so optimizations that are applied knowing that the object being animated.
So it it possible to do
var object = { x: 10, y: 0}
var objectEffect = new KeyframeEffect(object, [
{ x: 10, y: 0},
{ x: 20, y: 30}
], {
duration: 2000,
});
var anim = document.timeline.play(objectEffect);
anim.addEventListener('finish', function() {
console.log(object) // { x: 20, y: 30}
});