【发布时间】:2012-02-01 13:24:18
【问题描述】:
我想在鼠标悬停事件上调整大小并缓慢增长的画布元素(如弧线)。我该怎么做?
【问题讨论】:
标签: html canvas dom-events mouseover
我想在鼠标悬停事件上调整大小并缓慢增长的画布元素(如弧线)。我该怎么做?
【问题讨论】:
标签: html canvas dom-events mouseover
鼠标悬停在画布上?只需添加一个事件侦听器并按照您想要的方式重绘场景:
// Every time the mouse comes over the canvas the radius increases.
// you could even add a timer so that every time the mouse stays over
// the canvas the radius continues to increase constantly
can.addEventListener('mouseover', function(e) {
radius += 10;
ctx.clearRect(0,0,can.width, can.height);
ctx.beginPath();
ctx.arc(150, 150, radius, 0, Math.PI*.8, false);
ctx.stroke();
}, false);
将鼠标悬停在画布上绘制的“对象”上?你将不得不add object persistence and detection to the canvas。
【讨论】: