export default{
data: {
percentage: '', //百分比
animTime: '', // 动画执行时间
},
options:{
// 绘制圆形进度条方法
run(c, w, h) {
let that = this;
var num = (2 * Math.PI / 100 * c) - 0.5 * Math.PI;
that.data.ctx2.arc(w, h, w - 8, -0.5 * Math.PI, num); //每个间隔绘制的弧度
that.data.ctx2.setStrokeStyle("#ff5000");
that.data.ctx2.setLineWidth("16");
that.data.ctx2.setLineCap("butt");
that.data.ctx2.stroke();
that.data.ctx2.beginPath();
that.data.ctx2.setFontSize(40); //注意不要加引号
that.data.ctx2.setFillStyle("#ff5000");
that.data.ctx2.setTextAlign("center");
that.data.ctx2.setTextBaseline("middle");
that.data.ctx2.fillText(c + "%", w, h);
that.data.ctx2.draw();
},
/**
* start 起始百分比
* end 结束百分比
* w,h 其实就是圆心横纵坐标
*/
// 动画效果实现
canvasTap(start, end, time, w, h) {
var that = this;
start++;
if (start > end) {
return false;
}
that.run(start, w, h);
setTimeout(function () {
that.canvasTap(start, end, time, w, h);
}, time);
},
/**
* id----------------canvas画板id
* percent-----------进度条百分比
* time--------------画图动画执行的时间
*/
draw: function (id, percent, animTime) {
var that = this;
const ctx2 = wx.createCanvasContext(id);
that.setData({
ctx2:ctx2,
percentage:percent,
animTime: animTime
});
var time = that.data.animTime / that.data.percentage;
wx.createSelectorQuery().select('#'+id).boundingClientRect(function (rect) { //监听canvas的宽高
var w = parseInt(rect.width / 2); //获取canvas宽的的一半
var h = parseInt(rect.height / 2); //获取canvas高的一半,
that.canvasTap(0, that.data.percentage, time, w, h)
}).exec();
},
}
}
微信小程序使用canvas绘制进度条.zip
需积分: 2 88 浏览量
2024-01-11
21:34:47
上传
评论
收藏 3KB ZIP 举报
极致人生-010
- 粉丝: 3259
- 资源: 3077
最新资源
- 基于Java的在线教育平台设计源码
- 升降压斩波电路电路图,buck-boost电路图
- Python 程序语言设计模式思路-结构型模式:组合模式:将对象组合成树形结构
- 毕业设计基于python矩阵分解的推荐算法研究源码+详细文档+全部数据资料 高分项目.zip
- 基于网络的入侵检测系统源码+数据集+详细文档(高分毕业设计).zip
- 微信小程序源码 旅行故事分享 - 面包旅行App界面设计与文本展示资源下载
- 微信小程序源码 创意互动游戏 - 你画我猜App下载
- 摸底考试_学生版20230305.py
- 课程设计基于FPGA数字钟课程设计源码+课设报告(95分以上).zip
- 基于Java的企业家申报系统设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈