當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。