Created
August 3, 2016 22:09
-
-
Save bfgeek/375f28057797c4cf93cf234a0ca03406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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