Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Created June 10, 2018 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonekorean/1b5be0b9fc3ee9133ae8d0669bede1bd to your computer and use it in GitHub Desktop.
Save lonekorean/1b5be0b9fc3ee9133ae8d0669bede1bd to your computer and use it in GitHub Desktop.
Function to add velocity to bodies based on scroll speed
onScroll() {
this.scrollTimeout = null;
let delta = (this.lastOffset - window.pageYOffset) * this.options.scrollVelocity;
this.bodies.forEach((body) => {
Matter.Body.setVelocity(body, {
x: body.velocity.x + delta * this.randomize(this.options.xVarianceRange),
y: body.velocity.y + delta * this.randomize(this.options.yVarianceRange)
});
});
this.lastOffset = window.pageYOffset;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment