Install
npm i @thibka/mouse-speed
Usage
import MouseSpeed from "@thibka/mouse-speed";
const mouse_speed = new MouseSpeed( options );
function loop() {
requestAnimationFrame( loop );
mouse_speed.update(); // don't forget to update!
console.log(mouse_speed.x, mouse_speed.y);
}
Options
element
Default: window
The element over which the mouse speed will be returned.
max_amp
Default: 20
The mouse speed is based on the browser events movementX
and movementY
.
The value returned by those events can go up to more than 100.
This option lets you define a maximum amplitude to get smoother results.
increase_lerp_amt
Default: .01
Mouse speed is smoothed using linear interpolation.
To get a better control of your animation, you can use a specific lerp amount value when the speed is increasing.
decrease_lerp_amt
Default: .01
Same as increase_lerp_amt but applied when the speed is decreasing.