当前位置:网站首页>小程序 canvas 画布半圆环
小程序 canvas 画布半圆环
2022-04-23 02:07:00 【逸曦穆泽】
1、效果图:

2、wxml:
<view class="fragrance_item">
<view class="fragPos">
<view class="fragNum">{
{perfumePercent}}%</view>
<view class="fragText">香水余量</view>
</view>
<view class="fragPsoReset">
<view bindtap="resetTab" class="fragReset" hover-class="fragModel_hover">
<image class="fragReset_icon" src="/static/image/reset.png" mode="widthFix"> </image>
<view>复位</view>
</view>
</view>
<view class="fragRing">
<canvas id="perfumeBalance" type="2d" style="width: 220px; height: 120px;" ></canvas>
</view>
</view>
3、wxss:
.fragModel_hover{box-shadow: 0.2rem 0 0.3rem #8fd0e0, -0.2rem 0 0.3rem #58bfd1;}
.fragrance_item{position: relative;margin-left: 15px;margin-right: 15px;}
.fragPos{position: absolute;left: 50%; top: 50%;transform: translateX(-50%);text-align: center;}
.fragPos .fragNum{color:#32CD32;}
.fragPsoReset{position: absolute;right: 3px;top: 36px;text-align: center;}
.fragPsoReset .fragReset{display:inline-block;padding:8px 13px;background-color: rgba(50,80,80.68);border-radius: 15px;transition: all .3s ease-in;font-size: 12px;}
.fragPsoReset .fragReset_icon{width:22px;height:22px;}
.fragRing{width: 220px;height:120px;margin: auto;}
4、js:
let perfumeNum = 1.5;
Page({
data: {
perfumePercent: 0, // 香水余量
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
// 香水余量圆环
const query = wx.createSelectorQuery()
query.select('#perfumeBalance') .fields({ node: true, size: true }).exec((res) => {
that.initRing(res);
})
},
// b、香水余量
initRing(res) {
let that = this;
const canvas = res[0].node
const ctx = canvas.getContext('2d');
const dpr = wx.getSystemInfoSync().pixelRatio // 设备像素比
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr);
var circleR = 220 / 2; // 画布的一半,用来找中心点和半径
ctx.translate(0, 0); // 定义起始点
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// 取色圆环
ctx.beginPath();
ctx.strokeStyle = '#fff';//transparent
ctx.lineWidth = 12;
ctx.lineCap='round' // 设置圆环端点的形状
ctx.arc(circleR, circleR-10, circleR - 35, Math.PI, 2 * Math.PI, false);
ctx.stroke();
ctx.closePath();
console.log("香水余量")
// 进度_香水余量
ctx.beginPath(); // 起始一条路径,或重置当前路径
ctx.lineWidth = 6; // 线条宽度
ctx.lineCap='round' // 线条的结束端点样式
ctx.arc(circleR, circleR-10, circleR - 35, Math.PI,perfumeNum * Math.PI, false);
ctx.strokeStyle = "#00CED1";//transparent
ctx.stroke();
canvas.requestAnimationFrame(draw);
}
draw();
},
// 复位
resetTab(){
let that = this;
perfumeNum = 2; // 香水余量为100%
that.setData({
perfumePercent: 100,
})
},
})
版权声明
本文为[逸曦穆泽]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41408081/article/details/124328267
边栏推荐
- Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools
- Dynamic batch processing and static batch processing of unity
- Gray scale range corresponding to colors (red, yellow, green, blue, purple, pink, brick red and magenta) in HSV color space
- Common formatting problems after word writing
- Cc2541 emulator CC debugger tutorial
- Nanny level tutorial on building personal home page (II)
- 关于局域网浅谈
- Leetcode40 - total number of combinations II
- 在使用代理IP前需要了解哪些分类?
- Introduction to esp32 Bluetooth controller API
猜你喜欢

001_redis设置存活时间

What is BGP server and what are its advantages?

007_Redis_Jedis连接池

什么是api接口?

Leetcode46 Full Permutation

Introduction to micro build low code zero Foundation (lesson 2)
![leetcode:27. Remove element [count remove]](/img/af/e5cd9ef8dc43aab4ddf016600ffc4a.png)
leetcode:27. Remove element [count remove]

一些使用代理IP的小技巧。

How to write the resume of Software Test Engineer so that HR can see it?

拨号vps会遇到什么问题?
随机推荐
Basic knowledge of software testing, you can meet the interviewer after reading it
Use Xdebug breakpoint debugging in postman
What categories do you need to know before using proxy IP?
openstack 服务的启动
Halo open source project learning (I): project launch
2018 China Collegiate Programming Contest - Guilin Site J. stone game
World Book Day 𞓜 a good book that technicians should not miss (it cutting-edge technology)
Why is one plus one equal to two
不断下沉的咖啡业,是虚假的繁荣还是破局的前夜?
2022.4.20-----leetcode.388
Shardingsphere read write separation
What is a makefile file?
leetcode:27. 移除元素【count remove小操作】
[Dahua cloud native] micro service chapter - service mode of five-star hotels
006_redis_jedis快速入门
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
Dynamic batch processing and static batch processing of unity
Wechat public platform test number application, authorized login function and single sign on using hbuilder X and wechat developer tools
Cc2541 emulator CC debugger tutorial
Some tips for using proxy IP.