每當用戶在元素上移動鼠標指針時,都會調用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
相關用法
- JQuery mouseover()用法及代碼示例
- AngularJS ng-mouseover用法及代碼示例
- p5.js Element class()用法及代碼示例
- p5.js Element addClass()用法及代碼示例
- p5.js Element id()用法及代碼示例
- p5.js Element removeClass()用法及代碼示例
- p5.js Element mouseOut()用法及代碼示例
- p5.js Element hasClass()用法及代碼示例
- p5.js Element toggleClass()用法及代碼示例
- Lodash _.method()用法及代碼示例
- Node.js Http2ServerRequest.method用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 p5.js Element mouseOver() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。