Skip to content

Instantly share code, notes, and snippets.

@bfgeek
Created August 3, 2016 17:46
Show Gist options
  • Save bfgeek/d194154ade7bd5c168e801d62f0c8e4c to your computer and use it in GitHub Desktop.
Save bfgeek/d194154ade7bd5c168e801d62f0c8e4c to your computer and use it in GitHub Desktop.
registerAnimator('parallax', class {
animate(inputs, outputs) {
// read scroller vertical scroll offset.
const scrollTop = inputs.scroller.scrollTop;
// update parallax transform
let t = outputs.parallax.styleMap.get('transform').m42;
t = -0.2 * scrollTop;
outputs.parallax.styleMap.set('transform', new CSSTransformValue(... t));
}
});
// Main thread.
const animator = new Animator('parallax', /* inputs dictionary */ {
'scroller': new AnimatorScrollSource(elem1),
}, /* outputs dictionary */ {
'parallax': new AnimatorStyle(elem2, ['transform'])
});
animator.run();
aniator.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment