Home > WeChat Applet > Mini Program Development > WeChat mini program to create a custom circular progress bar

WeChat mini program to create a custom circular progress bar

PHPz
Release: 2017-04-02 15:13:08
Original
2468 people have browsed it

The article mainly introduces the detailed explanation of WeChat applet-custom circular Progress bar, which has certain reference value. The implementation idea is to first draw the bottom gray circle background, and then draw the upper blue progress strip.

JSCode:

Page({
 data: {},
 onLoad: function (options) {
  // 页面初始化 options为页面跳转所带来的参数
 },
 onReady: function () {
  
  // 页面渲染完成
  var cxt_arc = wx.createCanvasContext('canvasArc');//创建并返回绘图上下文context对象。
  cxt_arc.setLineWidth(6);
  cxt_arc.setStrokeStyle('#d2d2d2');
  cxt_arc.setLineCap('round')
  cxt_arc.beginPath();//开始一个新的路径
  cxt_arc.arc(106, 106, 100, 0, 2*Math.PI, false);//设置一个原点(106,106),半径为100的圆的路径到当前路径
  cxt_arc.stroke();//对当前路径进行描边
    
  cxt_arc.setLineWidth(6);
  cxt_arc.setStrokeStyle('#3ea6ff');
  cxt_arc.setLineCap('round')
  cxt_arc.beginPath();//开始一个新的路径
  cxt_arc.arc(106, 106, 100, -Math.PI * 1 / 2, Math.PI*6/5, false);
  cxt_arc.stroke();//对当前路径进行描边
  
  cxt_arc.draw();
    
 },
 onShow: function () {
  // 页面显示
 },
 onHide: function () {
  // 页面隐藏
 },
 onUnload: function () {
  // 页面关闭
 }
})
Copy after login

Page layout:

<view class="wrap">
 <view class="top">
  <canvas class="cir" style="width:212px; height:212px;" canvas-id="canvasArc">
  </canvas>
  
  <view class="cc">中间</view>
  
 </view>
</view>
Copy after login

CSS style:

.cir{
 display: inline-block;
 margin-top: 20rpx;
  
}
  
.top{
 text-align: center
}
  
.cc{
   
 margin-top: -120px;
   
}
Copy after login

The above is the detailed content of WeChat mini program to create a custom circular progress bar. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template