p5.js | mouseWheel() Function
The mouseWheel() function is invoked whenever a mouse or touchpad scroll causes a vertical mouse wheel event. This event can be accessed to determine the properties of the scroll. The delta property returns the amount of the scroll that took place. This value can be positive or negative depending on the direction of the scroll.
The callback function may have to end with the “return false;” statement to prevent any default behaviors that may be associated with scrolling on different browsers.
mouseWheel( event )
Parameters: This function accepts a single parameter as mentioned above and described below:
- event: This is an optional WheelEvent callback argument, that can be used to access scroll details.
Below examples illustrate the mouseWheel() function in p5.js:
Example 1: Using the scroll event to change the color when scrolled
Example 2: Displaying the scroll properties
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/