如何在鼠标悬停时调整画布元素的大小

时间:2012-02-01 13:24:18

标签: html5 javascript-events canvas

我想在mouseover事件上调整大小并缓慢增长大小的canvas元素(如弧形)。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

鼠标悬停在画布上?只需添加一个事件监听器并按照您想要的方式重绘场景:

// 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);

http://jsfiddle.net/dAQdL/

鼠标悬停在画布上绘制的“对象”?你必须add object persistence and detection to the canvas