Skip to content

Instantly share code, notes, and snippets.

@bfgeek
Created August 3, 2016 22:09
Show Gist options
  • Select an option

  • Save bfgeek/375f28057797c4cf93cf234a0ca03406 to your computer and use it in GitHub Desktop.

Select an option

Save bfgeek/375f28057797c4cf93cf234a0ca03406 to your computer and use it in GitHub Desktop.
// animation worklet
registerAnimator('parallaxAnim', class {
static inputs = {
'scroller': {
'scrollTop'
},
'parallax': {
'style': ['transform']
}
}
static outputs = {
'parallax': {
'style': ['transform']
}
}
animate(inputs, outputs) {
const scrollTop = inputs.scroller[0].scrollTop;
let t = inputs.parallax[0].styleMap.get('transform').m42;
t = -0.2 * scrollTop;
outputs.parallax[0].styleMap.set('transform', new CSSTransformValue(... t));
}
});
// css
.scroller {
animator: parallaxAnim scroller;
}
.parallaxEl {
animator: parallaxAnim parallax;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment