微信小程序实现圆形进度条动画
程序员文章站
2023-12-26 14:48:45
本文实例为大家分享了微信小程序动画之圆形进度条,供大家参考,具体内容如下
上图:
代码:
js:
//获取应用实例
var app = getapp(...
本文实例为大家分享了微信小程序动画之圆形进度条,供大家参考,具体内容如下
上图:
代码:
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" 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; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。