Skip to content

Instantly share code, notes, and snippets.

@niklasp
Last active December 3, 2021 16:39
Show Gist options
  • Save niklasp/25d6cf81d1158ed5038802fc48b6cc22 to your computer and use it in GitHub Desktop.
Save niklasp/25d6cf81d1158ed5038802fc48b6cc22 to your computer and use it in GitHub Desktop.
/* Scroll Velocity */
document.addEventListener( 'wheel', ( e ) => {
e.preventDefault()
this.scrollTarget = e.deltaY / 3
} );
//render()
this.direction = this.scroll > 0 ? -1 : 1
this.scroll -=(this.scroll - this.scrollTarget)*0.1
this.scroll *= 0.9
this.thumbs.forEach( th => {
th.position.x = this.calcPos(this.scroll, th.position.x)
})
/* Mouse Direction / Velocity (inside mousemove event) */
if ( this.lastMouseX === null || this.lastMouseY === null ) {
this.lastMouseX = e.clientX;
this.lastMouseY = e.clientY;
return;
}
const dx = e.clientX - this.lastMouseX;
const dy = e.clientY - this.lastMouseY;
this.dMouse = new THREE.Vector2( dx, dy );
this.lastMouseX = e.clientX;
this.lastMouseY = e.clientY;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment