组件代码
| <template> |
| <div class="battery"> |
| <div class="conver" :style="{'--progress': progress + '%'}"> |
| </div> |
| <div class="num">{{parseFloat(progress).toFixed(2)+'%'}}</div> |
| </div> |
| </template> |
| |
| <script> |
| export default { |
| props: { |
| progress:{ |
| type:Number, |
| default:0 |
| } |
| }, |
| data(){ |
| return { |
| |
| } |
| } |
| } |
| </script> |
| |
| <style scoped> |
| .num{ |
| z-index: 2; |
| color: #fff; |
| font-size: 24px; |
| } |
| .battery{ |
| position: relative; |
| display: flex; |
| justify-content: center; |
| align-items: center; |
| width: 100px; |
| height: 100px; |
| background-color: white; |
| border-radius: 50%; |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| .battery::after{ |
| content: ''; |
| position: absolute; |
| left: 0; |
| right: 0; |
| bottom: 0; |
| background-color: #4bb520; |
| border-radius: 50%; |
| |
| top:0% |
| |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| .conver{ |
| width: 100%; |
| height: 100%; |
| text-align: center; |
| color: #fff; |
| line-height: 125px; |
| position: absolute; |
| left: 0; |
| top: 0; |
| border-radius: 50%; |
| z-index: 1; |
| overflow: hidden; |
| } |
| .conver::before, |
| .conver::after{ |
| content: ''; |
| position: absolute; |
| left: -50%; |
| width: 200px; |
| height: 200px; |
| } |
| .conver::before{ |
| |
| background-color: #b37323; |
| opacity: 0.8; |
| border-radius: 40% 30%; |
| animation: rotate1 10s linear infinite; |
| } |
| .conver::after{ |
| |
| background-color: #b37323; |
| opacity: 0.7; |
| border-radius: 42% 40%; |
| animation: rotate2 10s linear infinite; |
| } |
| @keyframes rotate1{ |
| 0%{ |
| transform: rotate(0deg); |
| bottom: var(--progress); |
| } |
| 100%{ |
| transform: rotate(360deg); |
| |
| bottom: var(--progress); |
| } |
| } |
| @keyframes rotate2{ |
| 0%{ |
| transform: rotate(45deg); |
| bottom: var(--progress); |
| } |
| 100%{ |
| transform: rotate(360deg); |
| bottom: var(--progress); |
| } |
| } |
| </style> |
| |
复制
页面中使用
| <script> |
| import Battery from '@/components/Battery' |
| |
| export default { |
| name: 'App', |
| components:{ |
| Battery |
| } |
| } |
| </script> |
复制
| |
| <battery :progress="60"></battery> |
复制
页面效果(水波浮动)
- 截个图没有动态效果实际上是有的
