vue引用CSS样式实现手机充电效果

 更新时间:2024年01月05日 11:26:26   作者:范特西是只猫  
这篇文章主要介绍了vue引用CSS样式实现手机充电效果,本文通过示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

1. 实现效果

2. index.vue 页面

<template>
  <div class="home">
    <div class="body">
      <vab-charge :end-val="endVal" :start-val="startVal" />
    </div>
  </div>
</template>
<script>
  import VabCharge from '@/components/VabCharge'
export default {
  name: 'Demo',
  components: { VabCharge },
  data() {
    return {
      startVal: 0,
      endVal: 20,
      timeInterval: null,
    }
  },
  mounted() {
    this.timeInterval = setInterval(() => {
      if (this.endVal < 100) {
        this.startVal = this.endVal
        this.endVal++
      }
    }, 5000)
  },
  beforeDestroy() {
    if (this.clearInterval) {
      clearInterval(this.timeInterval)
    }
  },
  methods: {
  },
}
</script>
<style scoped lang="scss">
.home {
  .body {
    width: 890px;
    height: 500px;
    border: #00ffa2 solid 10px;
    box-sizing: border-box;
    // padding: 20px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    .qrcode2 {
    }
  }
}
</style>

3. VabCharge.vue 组件代码

<template>
  <div class="content">
    <div class="g-container" :style="styleObj">
      <div class="g-number">
        {{ endVal }}
      </div>
      <div class="g-contrast">
        <div class="g-circle"></div>
        <ul class="g-bubbles">
          <li v-for="(item, index) in 15" :key="index"></li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    name: 'VabCharge',
    props: {
      styleObj: {
        type: Object,
        default: () => {
          return {}
        },
      },
      startVal: {
        type: Number,
        default: 0,
      },
      endVal: {
        type: Number,
        default: 100,
      },
    },
    data() {
      return {
        decimals: 2,
        prefix: '',
        suffix: '%',
        separator: ',',
        duration: 3000,
      }
    },
    created() {},
    mounted() {},
    methods: {},
  }
</script>
<style lang="scss" scoped>
  .content {
    position: relative;
    display: flex;
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
    width: 100%;
    height: 100%;
    background: #000;
    .g-number {
      position: absolute;
      top: 27%;
      z-index: 99;
      width: 300px;
      font-size: 32px;
      color: #fff;
      text-align: center;
    }
    .g-container {
      position: relative;
      width: 300px;
      height: 400px;
      margin: auto;
    }
    .g-contrast {
      width: 300px;
      height: 400px;
      overflow: hidden;
      background-color: #000;
      filter: contrast(15) hue-rotate(0);
      animation: hueRotate 10s infinite linear;
    }
    .g-circle {
      position: relative;
      box-sizing: border-box;
      width: 300px;
      height: 300px;
      filter: blur(8px);
      &::after {
        position: absolute;
        top: 40%;
        left: 50%;
        width: 200px;
        height: 200px;
        content: '';
        background-color: #00ff6f;
        border-radius: 42% 38% 62% 49% / 45%;
        transform: translate(-50%, -50%) rotate(0);
        animation: rotate 10s infinite linear;
      }
      &::before {
        position: absolute;
        top: 40%;
        left: 50%;
        z-index: 99;
        width: 176px;
        height: 176px;
        content: '';
        background-color: #000;
        border-radius: 50%;
        transform: translate(-50%, -50%);
      }
    }
    .g-bubbles {
      position: absolute;
      bottom: 0;
      left: 50%;
      width: 100px;
      height: 40px;
      background-color: #00ff6f;
      filter: blur(5px);
      border-radius: 100px 100px 0 0;
      transform: translate(-50%, 0);
    }
    li {
      position: absolute;
      background: #00ff6f;
      border-radius: 50%;
    }
    @for $i from 0 through 15 {
      li:nth-child(#{$i}) {
        $width: 15 + random(15) + px;
        top: 50%;
        left: 15 + random(70) + px;
        width: $width;
        height: $width;
        transform: translate(-50%, -50%);
        animation: moveToTop #{random(6) + 3}s ease-in-out -#{random(5000) / 1000}s infinite;
      }
    }
    @keyframes rotate {
      50% {
        border-radius: 45% / 42% 38% 58% 49%;
      }
      100% {
        transform: translate(-50%, -50%) rotate(720deg);
      }
    }
    @keyframes moveToTop {
      90% {
        opacity: 1;
      }
      100% {
        opacity: 0.1;
        transform: translate(-50%, -180px);
      }
    }
    @keyframes hueRotate {
      100% {
        filter: contrast(15) hue-rotate(360deg);
      }
    }
  }
</style>

到此这篇关于vue通过CSS实现手机充电效果的文章就介绍到这了,更多相关vue手机充电内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • vue实现聊天框自动滚动的示例代码

    vue实现聊天框自动滚动的示例代码

    本文主要介绍了vue实现聊天框自动滚动的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-05-05
  • 详解VUE Element-UI多级菜单动态渲染的组件

    详解VUE Element-UI多级菜单动态渲染的组件

    这篇文章主要介绍了VUE Element-UI多级菜单动态渲染的组件,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-04-04
  • 解决vue项目运行提示Warnings while compiling.警告的问题

    解决vue项目运行提示Warnings while compiling.警告的问题

    这篇文章主要介绍了解决vue项目运行提示Warnings while compiling.警告的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-09-09
  • vue项目中jsonp跨域获取qq音乐首页推荐问题

    vue项目中jsonp跨域获取qq音乐首页推荐问题

    这篇文章主要介绍了vue项目中jsonp跨域获取qq音乐首页推荐问题,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2018-05-05
  • Vue插件实现过程中遇到的问题总结

    Vue插件实现过程中遇到的问题总结

    随着Vue.js越来越火,Vue.js 的相关插件也在不断的被贡献出来,数不胜数,这篇文章主要给大家介绍了关于Vue插件实现过程中遇到的问题,需要的朋友可以参考下
    2021-08-08
  • Vue子组件监听父组件值的变化

    Vue子组件监听父组件值的变化

    这篇文章主要介绍了Vue子组件监听父组件值的变化方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-04-04
  • elementUI Tree 树形控件单选实现示例

    elementUI Tree 树形控件单选实现示例

    在ElementUI中树形控件本身不支持单选功能,本文就来介绍一下如何实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2024-06-06
  • Vue.js 2.x之组件的定义和注册图文详解

    Vue.js 2.x之组件的定义和注册图文详解

    组件Component是 Vue.js 最强大的功能之一。组件可以扩展 HTML 元素,封装可重用的代码,这篇文章主要介绍了Vue.js 2.x:组件的定义和注册,需要的朋友可以参考下
    2018-06-06
  • VUE指令和pinia控制按钮权限示例详解

    VUE指令和pinia控制按钮权限示例详解

    这篇文章主要为大家介绍了VUE指令和pinia控制按钮权限示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-09-09
  • 十分钟封装一个好用的axios步骤示例

    十分钟封装一个好用的axios步骤示例

    这篇文章主要为大家介绍了十分钟封装一个好用的axios步骤示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-06-06

最新评论