【问题标题】:How to resize a canvas element on mouseover如何在鼠标悬停时调整画布元素的大小
【发布时间】:2012-02-01 13:24:18
【问题描述】:

我想在鼠标悬停事件上调整大小并缓慢增长的画布元素(如弧线)。我该怎么做?

【问题讨论】:

    标签: html canvas dom-events mouseover


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 2012-06-21
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      相关资源
      最近更新 更多