📜  p5.js 元素 mouseOut() 方法

📅  最后修改于: 2022-05-13 01:56:28.626000             🧑  作者: Mango

p5.js 元素 mouseOut() 方法

每当用户将鼠标指针移出元素时,都会调用 p5.js 中 p5.Element 的mouseOut()方法。它可用于将事件侦听器附加到元素。

句法:

mouseOut( fxn )

参数:此函数接受如上所述和如下所述的单个参数:

  • fxn:当鼠标从元素上移开时触发的函数。也可以将false值传递给它以防止前一个函数触发。

下面的示例说明了 p5.js 中的mouseOut() 方法

例子:

Javascript
function setup() {
    canv = createCanvas(550, 300);
    textSize(20);
  
    text("Move the mouse over the canvas " +
        "to change its color", 20, 20);
  
    canv.mouseOver(changeColor);
  
    // Specify the callback function
    // when the mouse is moved out of
    // an element
    canv.mouseOut(origColor);
}
  
function changeColor() {
    background("green");
  
    text("The mouse has been moved over " +
        "the canvas!", 20, 60);
  
    text("Move the mouse over the canvas " +
        "to change its color", 20, 20);
}
  
function origColor() {
    background("white");
  
    text("The mouse has been moved off " +
        "the canvas!", 20, 60);
  
    text("Move the mouse over the canvas to " +
        "change its color", 20, 20);
}


输出:

在线编辑器: https://editor.p5js.org/
环境设置: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
参考: https://p5js.org/reference/#/p5.Element/mouseOut