Applet custom round progress bar
- 2021-09-24 21:07:00
- OfStack
This article example for everyone to share the small program custom circular progress bar specific code, for your reference, the specific content is as follows
circle.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: 35vw;
position: absolute;
top: 33vw;
right: 0;
left: 0;
margin: auto;
border: 1px #000 solid;
border-radius: 5vw;
}
circle.wxml:
<view class="wrap">
<view class="circle-box">
<canvas class="circle" style="z-index: -99; width:200px; height:200px;" canvas-id="canvasCircle">
</canvas>
<canvas class="circle" style="width:200px; height:200px;" canvas-id="canvasArcCir">
</canvas>
<view class="draw_btn">
<view>80 Points </view>
<view>( Full marks 100 Points )</view>
</view>
</view>
</view>
circle.js:
// pages/circle/circle.js
// Get an application instance
const app = getApp()
var ctx = wx.createCanvasContext('canvasArcCir');
Page({
/**
* Initial data of the page
*/
data: {
},
drawCircle: function() {
function drawArc(s, e) {
ctx.setFillStyle('white');
ctx.clearRect(0, 0, 200, 200);
ctx.draw();
var x = 100,
y = 100,
radius = 96;
ctx.setLineWidth(5);
ctx.setStrokeStyle('#d81e06');
ctx.setLineCap('round');
ctx.beginPath();
// Center of a circle x,y Coordinates ,radius Radius s: Starting radian, unit radian (in 3 O 'Clock direction) e: Termination radian ,:false Is the direction of the radian counterclockwise
ctx.arc(x, y, radius, s, e, false);
ctx.stroke()
ctx.draw()
}
var step = 70,
startAngle = 1.5 * Math.PI,
endAngle = 0,
n = 100,
endAngle = step * 2 * Math.PI / n + 1.5 * Math.PI;
drawArc(startAngle, endAngle);
},
/**
* Life cycle function -- Listen for page loading
*/
onLoad: function(options) {
// Call the method of drawing a circle
this.drawCircle()
},
/**
* Life cycle function -- Listen to the initial rendering of the page
*/
onReady: function() {
// Create and return drawing context context Object.
var cxt_arc = wx.createCanvasContext('canvasCircle');
cxt_arc.setLineWidth(6);
cxt_arc.setStrokeStyle('#eaeaea');
cxt_arc.setLineCap('round');
cxt_arc.beginPath();
cxt_arc.arc(100, 100, 96, 0, 2 * Math.PI, false);
cxt_arc.stroke();
cxt_arc.draw();
},
})
I recommend a WeChat applet tutorial with high attention: "WeChat applet development tutorial". This site is carefully organized for everyone, and I hope I like it.