html 圆圈扩大动画,html5 – 使用Canvas为填充圆圈设置动画

剪裁区域使这非常容易.你所要做的就是制作一个圆形剪裁区域,然后填充一个大小的矩形,以获得一个值得填充的“部分圆”.这是一个例子:

var canvas = document.getElementById('Circle');

var context = canvas.getContext('2d');

var centerX = canvas.width / 2;

var centerY = canvas.height / 2;

var radius = 80;

var full = radius*2;

var amount = 0;

var amountToIncrease = 10;

function draw() {

context.save();

context.beginPath();

context.arc(centerX,false);

context.clip(); // Make a clipping region out of this path

// instead of filling the arc,we fill a variable-sized rectangle

// that is clipped to the arc

context.fillStyle = '#13a8a4';

// We want the rectangle to get progressively taller starting from the bottom

// There are two ways to do this:

// 1. Change the Y value and height every time

// 2. Using a negative height

// I'm lazy,so we're going with 2

context.fillRect(centerX - radius,centerY + radius,radius * 2,-amount);

context.restore(); // reset clipping region

context.beginPath();

context.arc(centerX,false);

context.lineWidth = 10;

context.strokeStyle = '#000000';

context.stroke();

// Every time,raise amount by some value:

amount += amountToIncrease;

if (amount > full) amount = 0; // restart

}

draw();

// Every second we'll fill more;

setInterval(draw,1000);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值