当前位置:网站首页>Applet canvas canvas half ring
Applet canvas canvas half ring
2022-04-23 02:07:00 【Yixi Muze】
1、 design sketch :
2、wxml:
<view class="fragrance_item">
<view class="fragPos">
<view class="fragNum">{
{perfumePercent}}%</view>
<view class="fragText"> Perfume allowance </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> Reset </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, // Perfume allowance
},
/**
* Life cycle function -- Monitor page loading
*/
onLoad: function (options) {
let that = this;
// Perfume margin ring
const query = wx.createSelectorQuery()
query.select('#perfumeBalance') .fields({ node: true, size: true }).exec((res) => {
that.initRing(res);
})
},
// b、 Perfume allowance
initRing(res) {
let that = this;
const canvas = res[0].node
const ctx = canvas.getContext('2d');
const dpr = wx.getSystemInfoSync().pixelRatio // Device pixel ratio
canvas.width = res[0].width * dpr
canvas.height = res[0].height * dpr
ctx.scale(dpr, dpr);
var circleR = 220 / 2; // Half of the canvas , Used to find the center point and radius
ctx.translate(0, 0); // Define the starting point
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
// Color ring
ctx.beginPath();
ctx.strokeStyle = '#fff';//transparent
ctx.lineWidth = 12;
ctx.lineCap='round' // Set the shape of the end of the ring
ctx.arc(circleR, circleR-10, circleR - 35, Math.PI, 2 * Math.PI, false);
ctx.stroke();
ctx.closePath();
console.log(" Perfume allowance ")
// speed of progress _ Perfume allowance
ctx.beginPath(); // Start a path , Or reset the current path
ctx.lineWidth = 6; // Line width
ctx.lineCap='round' // End style of line
ctx.arc(circleR, circleR-10, circleR - 35, Math.PI,perfumeNum * Math.PI, false);
ctx.strokeStyle = "#00CED1";//transparent
ctx.stroke();
canvas.requestAnimationFrame(draw);
}
draw();
},
// Reset
resetTab(){
let that = this;
perfumeNum = 2; // Perfume allowance 100%
that.setData({
perfumePercent: 100,
})
},
})
版权声明
本文为[Yixi Muze]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230207164830.html
边栏推荐
- Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs‘
- Hyperscan -- 2 compilation
- Heap overflow of kernel PWN basic tutorial
- 在使用代理IP前需要了解哪些分类?
- Nanny level tutorial on building personal home page (II)
- 2022.4.10-----leetcode. eight hundred and four
- leetcode:27. Remove element [count remove]
- Summary of I / O knowledge points
- 浅析一下隧道代理IP的优缺点。
- 006_redis_jedis快速入门
猜你喜欢
什么是bgp服务器,有哪些优势?
Unicorn bio raised $3.2 million to turn prototype equipment used to grow meat into commercial products
Find the largest number of two-dimensional arrays
leetcode:27. Remove element [count remove]
LeetCode 447. Number of boomerangs (permutation and combination problem)
006_redis_jedis快速入门
Thinkphp内核开发盲盒商城源码v2.0 对接易支付/阿里云短信/七牛云存储
What businesses use physical servers?
Heap overflow of kernel PWN basic tutorial
拨号服务器是什么,有什么用处?
随机推荐
Realize linear regression with tensorflow (including problems and solutions in the process)
arduino esp8266 网络升级 OTA
Use of push() and pop()
hyperscan --- 1
浅析一下隧道代理IP的优缺点。
从开源爱好者到 Apache 董事,一共分几步?
[assembly language] understand "stack" from the lowest point of view
Kubernetes cluster installation based on Kirin SP10 server version
What business scenarios will the BGP server be used in?
C standard library - < time h>
用TensorFlow实现线性回归(包括过程中出现的问题及解决方法)
On LAN
How does Axure set the content of the text box to the current date when the page is loaded
Echo "new password" |passwd -- stdin user name
Communication summary between MCU and 4G module (EC20)
浅析静态代理ip的三大作用。
Analyze the advantages and disadvantages of tunnel proxy IP.
想体验HomeKit智能家居?不如来看看这款智能生态
How to classify proxy IP?
从0开始开发一个chrome插件(2)