⼩程序实现圆形进度条动画本⽂实例为⼤家分享了⼩程序动画之圆形进度条,供⼤家参考,具体内容如下
上图:
代码:
js:
//获取应⽤实例
var app = getApp()
var interval;
var varName;
var ctx = wx.createCanvasContext('canvasArcCir');
Page({
data: {
},
drawCircle: function () {
clearInterval(varName);
function drawArc(s, e) {
ctx.setFillStyle('white');
ctx.clearRect(0, 0, 200, 200);
ctx.draw();
var x = 100, y = 100, radius = 96;
ctx.setLineWidth(7);
ctx.setStrokeStyle('#BFEFFF');
ctx.setLineCap('round');
ctx.beginPath();
ctx.arc(x, y, radius, s, e, false);
ctx.stroke()
ctx.draw()
}
var step = 1, startAngle = 1.5 * Math.PI, endAngle = 0;
var animation_interval = 1000, n = 60;
var animation = function () {
if (step <= n) {
endAngle = step * 8 * Math.PI / n + 1.5 * Math.PI;
drawArc(startAngle, endAngle);
step++;
} else {
clearInterval(varName);
}
};
varName = setInterval(animation, animation_interval);
},
onReady: function () {
//创建并返回绘图上下⽂context对象。
var cxt_arc = wx.createCanvasContext('canvasCircle');
cxt_arc.setLineWidth(8);
cxt_arc.setStrokeStyle('#EDEDED');
cxt_arc.setLineCap('round');
cxt_arc.beginPath();
cxt_arc.arc(100, 100, 96, 0, 2 * Math.PI, false);
cxt_arc.stroke();
cxt_arc.draw();
},
onLoad: function (options) {
}
})
wxml:
<view class="wrap">
<view class="circle-box">
<canvas class="circle" canvas-id="canvasArcCir">
</canvas>
<canvas class="circle" canvas-id="canvasCircle">
</canvas>
<view class="draw_btn" bindtap="drawCircle">点击开始</view>
</view>
</view>
wxss:
page {
width: 100%;
height: 100%;
background-color: #fff;
}
.circle-box {
text-align: center;
margin-top: 10vw;
}
.circle {
position: absolute;
left: 0;
canvas动画right: 0;
margin: auto;
}
.draw_btn {
width: 28vw;
position: absolute;
top: 31vw;
right: 0;
left: 0;
margin: auto;
border: 1px #0D0D0D solid;
background-color: #BFEFFF;
border-radius: 5vw;
}
为⼤家推荐现在关注度⽐较⾼的⼩程序教程⼀篇:⼩编为⼤家精⼼整理的,希望喜欢。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论