search
HomeWeChat AppletMini Program DevelopmentWeChat mini program to create a custom circular progress bar

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 () {
  // 页面关闭
 }
})

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>

CSS style:

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

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft