【问题标题】:canvas .stroke() animate draw html5canvas .stroke() 动画绘制 html5
【发布时间】:2012-12-11 09:15:05
【问题描述】:

http://jsfiddle.net/jfrazelle/bZec4/3/ 如何使箭头的绘制动画化,如何减慢 .stroke() 的速度。我希望这个箭头在绘制时被绘制和动画化。

drawArrow('arrow-1', 50, 50, 100, 10, 100);

function drawArrow(id, sx, sy, ex, ey, fx){
    var arrow = document.getElementById(id);
    var ctx_1 = arrow.getContext('2d');
    ctx_1.clearRect(0, 0, arrow.width, arrow.height);
    ctx_1.beginPath();
    ctx_1.moveTo(10,ey);
    ctx_1.quadraticCurveTo(sx, sy, ex, ey);
    ctx_1.stroke();

    var ang = findAngle(sx, sy, fx, ey);
    drawArrowhead(ctx_1, fx, ey, ang, 15, 15);
}

function drawArrowhead(ctx, locx, locy, angle, sizex, sizey) {
    var hx = sizex / 2;
    var hy = sizey / 2;
    ctx.translate((locx ), (locy));
    ctx.rotate(angle);
    ctx.translate(-hx,-hy);
    ctx.beginPath();
    ctx.moveTo(0,0);    
    ctx.lineTo(0.5*sizex,1.0*hy);
    ctx.lineTo(0.5,1.0*sizey);
    ctx.stroke();
}

// returns radians
function findAngle(sx, sy, ex, ey) {
    // make sx and sy at the zero point
    return Math.atan2((ey - sy) , (ex - sx));
}

【问题讨论】:

    标签: jquery html canvas


    【解决方案1】:

    您可能想使用 requestAnimFrame。看here.

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 2011-04-28
      • 1970-01-01
      • 2012-05-12
      • 2015-08-18
      • 1970-01-01
      • 2011-12-25
      • 1970-01-01
      • 2017-12-21
      相关资源
      最近更新 更多