每当用户在元素上移动鼠标指针时,都会调用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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。