Last active
December 3, 2021 16:39
-
-
Save niklasp/25d6cf81d1158ed5038802fc48b6cc22 to your computer and use it in GitHub Desktop.
This file contains 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
/* 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