当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


p5.js Element mouseOver()用法及代码示例


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

用法:

mouseOver( fxn )

参数:该函数接受如上所述和以下描述的单个参数:

  • fxn:每当鼠标移到元素上时,都会触发该函数。还可以将false值传递给它,以防止触发先前的函数。

以下示例说明了p5.js中的mouseOver()方法:

例:



Javascript

function setup() { 
    canv = createCanvas(550, 300); 
    textSize(20); 
  
    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); 
    divelem.style("border:2px dashed"); 
  
    // Using the mouseOver() method 
    // for a callback to changeColor() 
    divelem.mouseOver(changeColor); 
} 
  
function changeColor() { 
    divelem.style( 
        "background-color:lightgreen"
    ); 
  
    divelem.html( 
        "The mouse has been moved over the element!"
    ); 
}

输出:

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

相关用法


注:本文由纯净天空筛选整理自sayantanm19大神的英文原创作品 p5.js Element mouseOver() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。