说明
将鼠标设置为预定的符号或图像。
注意:如果你想要将鼠标设置为图像,建议的图像大小为 16x16 或 32x32 像素。同时,该功能并非适用于所有浏览器,参数 x 及 y 必须低于图像的大小。
范例
function setup() {
}
// 更换鼠标在四象限中的图标
function draw() {
line(width / 2, 0, width / 2, height);
line(0, height / 2, width, height / 2);
if (mouseX < 50 && mouseY < 50) {
cursor(CROSS);
} else if (mouseX > 50 && mouseY < 50) {
cursor('progress');
} else if (mouseX > 50 && mouseY > 50) {
cursor('https://sh-cdn-tos.aleshu.com/ickerlab_storages/userid_355/2023-11-19/1700430932_55b39133be03c794180562b936ab0d88.png');
} else {
cursor('grab');
}
}
new p5();
语法
cursor(type, [x], [y])
参数
type
字符串|常量:ARROW、CROSS、HAND、MOVE、TEXT 或图像的路径
x
数字:鼠标的横向活跃点
y
数字:鼠标的纵向活跃点