Skip to content

Instantly share code, notes, and snippets.

@bfgeek
Created August 3, 2016 17:51
Show Gist options
  • Save bfgeek/f365eda80b08b9a0040b4267c3028731 to your computer and use it in GitHub Desktop.
Save bfgeek/f365eda80b08b9a0040b4267c3028731 to your computer and use it in GitHub Desktop.
registerAnimator('parallax', class {
static inputs = {
'scroller': ScrollSource;
};
static outputs = {
'parallax': Style(['transform']) // This is bad.
}
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': elem1,
}, /* outputs dictionary */ {
'parallax': elem2,
});
animator.run();
aniator.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment