Skip to content
Related Articles

Related Articles

Improve Article

p5.js Element mouseOver() Method

  • Last Updated : 20 Nov, 2020

The mouseOver() method of p5.Element in p5.js is invoked whenever the user moves the mouse pointer on the element. It can be used to attach event listeners to an element.


mouseOver( fxn )

Parameters: This function accepts a single parameter as mentioned above and described below:

  • fxn: It is a function to be fired whenever the mouse is moved onto the element. A value of false can also be passed to it for preventing the previous function to fire.

The example below illustrates the mouseOver() method in p5.js:



function setup() {
    canv = createCanvas(550, 300);
    text("Move the mouse over the element "
        + "to change its color", 20, 20);
    divelem =
        createDiv("This is a div element");
    divelem.position(30, 80);
    divelem.size(400, 200);"border: 2px dashed");
    // Using the mouseOver() method
    // for a callback to changeColor()
function changeColor() {
        "background-color: lightgreen"
        "The mouse has been moved over the element!"


Online editor:
Environment Setup:

My Personal Notes arrow_drop_up
Recommended Articles
Page :