正在处理.js - 当鼠标离开画布时继续交互
Processing.js - Continue interacting when mouse is out of canvas
我的标题上有一个画布,当用户将鼠标悬停在画布上时,他/她可以与画布进行交互。当鼠标离开画布时,交互停止。当用户浏览网站时,当鼠标在整个文档中移动时,是否可以将交互保持在画布之外。
我正在使用处理.js我不知道编写处理(我没有编写我提供的代码)。我搜索了很多,自己尝试了一下mouseOut()
但没有运气。
代码 :
int factor = 2;
int bufferY = 20;
int bufferX = 10;
void setup()
{
size(700, 200);
strokeCap(SQUARE);
}
void draw()
{
background(255);
ArrayList<Linus> linus = new ArrayList<Linus>();
for (int x=0; x<coordsArray.length; x++)
{
Linus l = new Linus(coordsArray[x][0]*factor+bufferX, coordsArray[x][1]*factor+bufferY, coordsArray[x][2]*factor+bufferX, coordsArray[x][3]*factor+bufferY);
linus.add(l);
}
for (int x=0; x<coordsArray.length; x++)
{
linus.get(x).draw();
}
}
class Linus
{
float sX, sY, eX, eY;
Linus(float _sX, float _sY, float _eX, float _eY)
{
sX = _sX;
sY = _sY;
eX = _eX;
eY = _eY;
}
void draw()
{
float weight = 1;
weight = map(mouseX, 0, width, 1, 40);
strokeWeight(weight);
line(sX+weight/2, sY, eX+weight/2, eY);
}
}
float[][] coordsArray =
{
{40 ,0 ,0 ,80},
{43 ,6 ,6 ,80},
{46 ,12 ,42 ,20},
{30 ,44 ,24 ,56 },
{49 ,18 ,45 ,26},
{36 ,44 ,30 ,56 },
{52 ,24 ,48 ,32},
{42 ,44 ,36 ,56 },
{55 ,30 ,51 ,38},
{48 ,44 ,42 ,56 },
{58 ,36 ,48 ,56},
{61 ,42 ,42 ,80},
{88 ,0 ,48 ,80},
{94 ,0 ,54 ,80},
{100 ,0 ,95 ,10},
{78 ,44 ,72 ,56 },
{106 ,0 ,101 ,10},
{84 ,44 ,78 ,56 },
{110 ,4 ,105 ,14},
{90 ,44 ,84 ,56 },
{113 ,10 ,90 ,56},
{116 ,16 ,102 ,44},
{98 ,52 ,93 ,62},
{119 ,22 ,112 ,36},
{102 ,56 ,96 ,68},
{136 ,0 ,133 ,6},
{105 ,62 ,99 ,74},
{142 ,0 ,137 ,10},
{108 ,68 ,102 ,80},
{148 ,0 ,143 ,10},
{111 ,74 ,108 ,80},
{154 ,0 ,149 ,10},
{160 ,0 ,120 ,80},
{166 ,0 ,126 ,80},
{172 ,0 ,167 ,10},
{178 ,0 ,173 ,10},
{184 ,0 ,179 ,10},
{188 ,4 ,185 ,10},
{194 ,4 ,159 ,74},
{202 ,0 ,162 ,80},
{208 ,0 ,203 ,10},
{186 ,44 ,180 ,56},
{173 ,70 ,168 ,80 },
{214 ,0 ,209 ,10},
{192 ,44 ,186 ,56},
{179 ,70 ,174 ,80 },
{220 ,0 ,215 ,10},
{198 ,44 ,192 ,56},
{185 ,70 ,180 ,80 },
{224 ,4 ,221 ,10},
{191 ,70 ,186 ,80},
{197 ,70 ,192 ,80},
{231 ,14 ,205 ,66},
{242 ,4 ,207 ,74},
{250 ,0 ,242 ,16},
{219 ,62 ,210 ,80},
{256 ,0 ,251 ,10},
{221 ,70 ,216 ,80},
{262 ,0 ,257 ,10},
{227 ,70 ,222 ,80},
{268 ,0 ,263 ,10},
{233 ,70 ,228 ,80},
{272 ,4 ,269 ,10},
{239 ,70 ,234 ,80},
{245 ,70 ,242 ,76},
{286 ,0 ,246 ,80},
{292 ,0 ,252 ,80},
{276 ,44 ,270 ,56},
{282 ,44 ,276 ,56},
{288 ,44 ,282 ,56},
{316 ,0 ,276 ,80},
{322 ,0 ,282 ,80}
};
我找到了解决方案。
我把它放在我的 pde 文件中:
window.onmousemove = handleMouseMove;
function handleMouseMove(event) {
event = event || window.event;
mouseX = event.clientX;
mouseY = event.clientY;
}
我必须改变一下在画布上绘图的方式,但至少当我将鼠标移动到画布之外时它会移动。
谢谢!
更新:
我也改变宽度和高度:
width = document.documentElement.clientWidth;
height = document.documentElement.clientHeight;
相关文章:
- 离开页面时弹出消息
- 当主导航离开视图时,为粘性导航应用样式
- 如何在离开标签时停止在标签中播放紫藤视频
- 如何在视图中保存用户输入内容,并在离开页面时对控制器进行后期调用
- 在 jquery 移动中离开页面时结束 SetInterval 函数
- 当光标离开屏幕时,游戏不会't以Javascript结尾
- Jquery:当鼠标指针进入和离开元素时,创建一个弹出窗口
- Angular 2:当我离开路由时,如何应用回调
- 离开url时淡出页面(以及登录时淡入页面)
- 如果表单已填写,请在离开页面时确认警报
- Socket.io - 离开房间时延迟
- 正在处理.js - 当鼠标离开画布时继续交互
- 如何在用户离开网页时显示模态窗口
- 当用户在移动 Safari 浏览器上离开页面时暂停声音
- 当用户离开页面时调用 JavaScript 函数
- VueJS & Laravel,在用户离开屏幕时发出后请求
- 离开网站时弹出
- 聊天应用程序 - 当有人进入/离开房间时,用声音通知用户
- JavaScript 事件仅在离开站点时发生
- 用户离开页面时的事件