微信小程序 圆形进度条

3 篇文章 0 订阅
2 篇文章 0 订阅

圆形进度条 常用组件

下面展示:

画布 链接.
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();
 //画圆arc(圆心x坐标,圆心y轴,半径,开始弧度,结束弧度,方向默认顺时针)
 ctx.arc(x, y, radius, s, e, false);
 ctx.stroke()
 ctx.draw()
 }
 var step = 1, startAngle = 1.5 * Math.PI, endAngle = 0;
 //n是时间可传递参数设置
 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);
 }
 };
 //setInterval函数按照周期animation_interval运行animation
 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" style="width:200px; height:200px;" canvas-id="canvasArcCir">
 </canvas>
 <canvas class="circle" style="z-index: -5; width:200px; height:200px;" 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;
 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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值