写一个电量组件

battery.vue

<template><div><canvas ref="mycanvas" :width="cWidth" :height="cHeight"></canvas></div>
</template><script>
export default {name: 'battery',mycanvas: null,ctx: null,myInterval: null,props: {proQuantity: {type: Number,default: 50},proIsCharge: {type: Boolean,default: false}},data () {return {cWidth: 66,cHeight: 28,jd: 0}},created () {},watch: {// 监听是否变化电量 ,如果是 做一个充电动画proIsCharge (newVal, oldVal) {console.log('======proIsCharge============', newVal)let _this = thisclearInterval(_this.myInterval)this.jd = 0if (_this.proIsCharge) {_this.myInterval = setInterval(function () {_this.drawCharge()}, 300)}}},mounted () {this.mycanvas = this.$refs.mycanvasthis.ctx = this.mycanvas.getContext('2d')this.drawBg()this.drawPath(this.proQuantity)},methods: {// 画一个背景drawBg () {this.ctx.strokeStyle = 'rgba(255,255,255,1)'this.ctx.lineWidth = 2this.ctx.strokeRect(0, 0, 60, 28)this.ctx.fillStyle = 'rgba(0,0,0,0.2)'this.ctx.fillRect(0, 0, 60, 28)this.ctx.fillStyle = 'rgba(255,255,255,1)'this.ctx.fillRect(61, 7, 6, 14)},// 根据电量画出一个块drawPath (quantity) {if (this.proIsCharge) {this.ctx.fillStyle = 'green'} else if (quantity < 20) {this.ctx.fillStyle = 'red'} else {this.ctx.fillStyle = 'green'}this.ctx.fillRect(1, 1, (60 - 2) * quantity / 100, 26)},drawCharge () {this.ctx.clearRect(0, 0, this.cWidth, this.cHeight)this.drawBg()this.jd = this.jd + 10if (this.jd > 100) {this.jd = 0}this.drawPath(this.jd)}}
}
</script><style scoped></style>

主页面引用
比较简单

<battery style=" width: 90px;height: 30px;" :proIsCharge="IsCharge" :proQuantity="batteryEnegy"></battery>

更改batteryEnegy显示电量值 充电时更改IsCharge为true

效果图

vue中用canvas画移动端电量显示 实现充电动画相关推荐

  1. vue中用canvas实现移动端手写板、电子签名功能

    html部分: js部分: css部分:

  2. 新H5中用canvas画一个数字钟表

    此文章是参考以往大牛代码,在大牛代码基础上加以更改而成. 本人暂时还是一名技术菜鸟,刚刚踏上web前端这条路才五个月,希望大牛们多多提携... 效果图如下: 话不多说,上代码: <body st ...

  3. html画圆圈原理,【已解决】HTML中用Canvas画圆圈

    折腾: [未解决]vuejs的vue-admin-template中自己手动实现画出类似电路图的控制面板图 期间,再去canvas中圆圈 如图: 希望画出大大小小的各种圆圈 包括圆圈里面还带东西的.c ...

  4. 在小程序中用canvas画一个仪表盘

    本意是打算写一个类似f2的半圆进度条,但是感觉小程序中引入太难调了,所以就自己用canvas随便画了一个实现了类似的效果. 最终效果图 wxml <view class="top-bo ...

  5. vue使用canvas画图画不出来

    使用vue做一个手势密码,相当于手机图案解锁 canvas要占全屏所以获取宽高赋值 使用canvas画图,绘制图案 代码 <template><div id="handlo ...

  6. 移动端html5手写板,Vue利用canvas实现移动端手写板的方法

    清除 保存 Canvas画板 var draw; var preHandler = function(e){e.preventDefault();} class Draw { constructor( ...

  7. canvas画奥运五环 2019/10/29

    在HbuilderX中用canvas画一个奥运五环. 先用arc画出五个圆环,画布是后画的图形在顶层,再根据圆环相互串压的顺序,新添同心圆笔画,就能画出五环相互勾连的样子了. 基本完成任务,效果简陋, ...

  8. 06.MTK关机充电动画显示

    关机充电的第一张logo: /vendor/mediatek/proprietary/bootable/bootloader/lk/dev/logo/rules.mk RESOURCE_OBJ_LIS ...

  9. 移动端html5手写板,Vue+canvas实现移动端手写板步骤详解

    这次给大家带来Vue+canvas实现移动端手写板步骤详解,Vue+canvas实现移动端手写板的注意事项有哪些,下面就是实战案例,一起来看一下. 清除 保存 Canvas画板 var draw; v ...

最新文章

  1. asp.net下的串口编程
  2. 判断long类型是否为空_数据类型
  3. SAP内部订单的作用
  4. php str_replace多个参数,php str_replace()函数的用法,有那些参数?
  5. 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit
  6. 计算机应用基础作业2客观题,《计算机应用基础》作业2.doc
  7. linux网络命令详解
  8. 开源自动化配置管理工具Puppet入门教程
  9. SDN是什么,与传统分布式网络有什么区别
  10. 《c语言南开100题》,二级C语言南开100题 免费
  11. vue子父组件之间的传值
  12. 计算机主板扩展槽,计算机内部所有插槽介绍,10分钟读懂电脑主板,高手必备!...
  13. 微信公众号接口调用php示例,php微信公众号js-sdk开发应用_php实例
  14. VR眼镜连接android设备,华为VR眼镜连接电脑教程
  15. 脸上长了黄褐斑怎么办
  16. Python 基础代码
  17. 配置文档的访问权限 配置LDAP家目录漫游
  18. VC2005操作Word
  19. 小程序 获取微信、手机设备、账号等信息api
  20. 要鲧?还是要禹?中华民族生存大问题!(转自四川新闻网)

热门文章

  1. 举简单例子秒懂虚拟机快照功能
  2. js render 函数
  3. 基于Hexo框架快速搭建个人博客--文章一键发布(五)
  4. 苹果手机获取基站信息
  5. 在linux中删除多级目录,如何在Linux中删除目录
  6. 关于 Jenkins 的 Unity 3D Plugin
  7. asterisk的基本配置
  8. Javanbsp;动画制作
  9. PS图像如何转换为位图模式?
  10. 宇视网络视频录像机运动检测告警推送到手机客户端