本文实例为大家分享了Vue中使用js制作进度条式数据对比动画的具体代码,供大家参考,具体内容如下

实现的效果:(初始化以及浏览器resize的时候两侧的条形为向两侧递增的动画,其中两端的数字也是递增的动画)

HTML部分:

<div class="no-ivatargo-chart-b">
  <div class="investment-ability">
    <div class="title">
      <span>您的投资能力分析</span>
    </div>
    <div class="investment-ability-picture-outer-container">
      <div class="investment-ability-picture-container">
        <div class="investment-ability-picture-header"
             ref="allLine">
          <span>我</span>
          <span>平均</span>
        </div>
        <div class="investment-ability-picture"
             v-for="(item, index) in abilityArr"
             :key="index">
          <div class="investment-ability-picture-top">
            <div class="investment-left">
              <div class="left-icon-outer">
                <div class="left-icon-inner"></div>
              </div>
              <span>{{item.title}}</span>
            </div>
            <div class="investment-right">
              <div class="investment-info">
                <span class="my-color">{{item.score | scoreFilter}}</span>
                <div class="all-line">
                  <div class="my-line"
                       :style="{'width': item.myWidth}"></div>
                  <div class="other-line"
                       :style="{'width': item.averageWidth}"></div>
                </div>
                <span class="average-color">{{item.average | scoreFilter}}</span>
              </div>
            </div>
          </div>
        </div>
        <div class="investment-ability-picture-footer">
          <span>100</span>
          <span>0</span>
          <span>100</span>
        </div>
      </div>
    </div>
  </div>
</div>
filters: {
  scoreFilter (val) {
    if (!isNaN(val)) {
      return Number(val) < 10 ? `0${parseInt(val)}` : parseInt(val)
    } else {
      return ''
    }
  }
}

CSS部分:

.no-ivatargo-chart-b {
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 14.76px;
  color: #bfbfbf;
  background-color: #0f1318;
  .title {
    display: flex;
    align-items: center;
    font-size: 17.22px;
    color: #bfbfbf;
    margin-bottom: 15px;
  }
  .investment-ability-picture-header {
    width: 400px;
    margin-left: 130px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin-bottom: 10px;
    color: #fff;
  }
  .investment-ability-picture-outer-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100% - 50px);
    .investment-ability-picture-container {
      display: flex;
      flex-direction: column;
      .investment-ability-picture {
        display: flex;
        flex-direction: column;
        margin-bottom: 10px;
        .investment-ability-picture-top {
          display: flex;
          .investment-left {
            font-size: 14.76px;
            color: #bfbfbf;
            width: 100px;
            display: flex;
            align-items: center;
            .left-icon-outer {
              width: 14px;
              height: 14px;
              background-color: #3fb050;
              border-radius: 50%;
              position: relative;
              margin-right: 5px;
              .left-icon-inner {
                position: absolute;
                width: 5px;
                height: 5px;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                background-color: #fff;
                border-radius: 50%;
              }
            }
          }
          .investment-right {
            display: flex;
            align-items: center;
            justify-content: space-between;
            .investment-info {
              display: flex;
              align-items: center;
              justify-content: space-between;
              .all-line {
                width: 400px;
                height: 10px;
                background-color: #57606e;
                border-radius: 2px;
                margin-left: 10px;
                margin-right: 10px;
                position: relative;
                .my-line {
                  width: 0;
                  height: 10px;
                  position: absolute;
                  top: 0;
                  right: 200px;
                  background-color: #f5a623;
                  border-top-left-radius: 2px;
                  border-bottom-left-radius: 2px;
                }
                .other-line {
                  width: 0;
                  height: 10px;
                  position: absolute;
                  top: 0;
                  left: 200px;
                  background-color: #1890ff;
                  border-top-right-radius: 2px;
                  border-bottom-right-radius: 2px;
                }
              }
              .my-color {
                width: 20px;
                color: #f5a623;
              }
              .average-color {
                width: 20px;
                color: #1890ff;
              }
            }
          }
        }
        .investment-ability-picture-bottom {
          display: flex;
          flex-direction: column;
          background-color: #ccc;
          width: 400px;
          margin-left: 130px;
          padding: 5px;
          color: #000;
        }
      }
    }
  }
  .investment-ability-picture-footer {
    width: 400px;
    margin-left: 130px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
  }
}

JS部分:

1.子组件当中

mounted () {
  let that = this
  window.onresize = () => {
    clearTimeout(that.resizeTimer)
    that.resizeTimer = setTimeout(() => {
      that.handleGetAllWidth()
    }, 1000)
  }
  this.$nextTick(() => {
    clearTimeout(this.resizeTimerB)
    this.resizeTimerB = setTimeout(() => {
      this.handleGetAllWidth()
    }, 200)
  })
}
 
// methods当中
handleGetAllWidth () {
  this.$emit('getAllWidth', this.$refs.allLine.offsetWidth)
}

2.父组件当中

getAllLineWidth (data) {
  this.allLineWidth = data
  this.calculateIvatargo()
},
// 给条形图添加计算宽度,并形成动画
calculateIvatargo () {
  this.myTimerArr.forEach((value, index) => {
    clearInterval(value)
  })
  this.averageTimerArr.forEach((value, index) => {
    clearInterval(value)
  })
  this.myTimerArr = []
  this.averageTimerArr = []
  let myVal = []
  let averageVal = []
  this.myAbilityArr.forEach((value, index) => {
    myVal[index] = 0
    averageVal[index] = 0
    this.myTimerArr[index] = setInterval(() => {
      if (myVal[index] > Number(this.allLineWidth) * Number(value.score) / 200 || !value.score) {
        clearInterval(this.myTimerArr[index])
        value.score ? myVal[index] = Number(this.allLineWidth) * Number(value.score) / 200 : myVal[index] = 0
        this.$set(value, 'myWidth', myVal[index]   'px')
        this.$set(value, 'myNum', value.score)
      } else {
        myVal[index]  
        this.$set(value, 'myWidth', myVal[index]   'px')
        this.$set(value, 'myNum', myVal[index] / 2)
      }
    }, 5)
    this.averageTimerArr[index] = setInterval(() => {
      if (averageVal[index] > Number(this.allLineWidth) * Number(value.average) / 200 || !value.average) {
        clearInterval(this.averageTimerArr[index])
        value.average ? averageVal[index] = Number(this.allLineWidth) * Number(value.average) / 200 : averageVal[index] = 0
        this.$set(value, 'averageWidth', averageVal[index]   'px')
        this.$set(value, 'averageNum', value.average)
      } else {
        averageVal[index]  
        this.$set(value, 'averageWidth', averageVal[index]   'px')
        this.$set(value, 'averageNum', averageVal[index] / 2)
      }
    }, 5)
  })
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持Devmax。

Vue中使用js制作进度条式数据对比动画的更多相关文章

  1. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  2. html5 拖拽及用 js 实现拖拽功能的示例代码

    这篇文章主要介绍了html5 拖拽及用 js 实现拖拽,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  3. amaze ui 的使用详细教程

    这篇文章主要介绍了amaze ui 的使用详细教程,本文通过多种方法给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

  4. swift皮筋弹动发射飞机ios源码

    这是一个款采用swift实现的皮筋弹动发射飞机游戏源码,游戏源码比较详细,大家可以研究学习一下吧。

  5. Swift与Js通过WebView交互

    开发环境:Swfit2.3XCode8.2基础概念jscontext,jscontext是代表JS的执行环境,通过-evaluateScript:方法就可以执行一JS代码JSValue,JSValue封装了JS与ObjC中的对应的类型,以及调用JS的API等JSExport,JSExport是一个协议,遵守此协议,就可以定义我们自己的协议,在协议中声明的API都会在JS中暴露出来,才能调用Swif

  6. JSCore swift

    如果双方相互引用,会造成循环引用,而导致内存泄露。以上是Jscore的基本使用,比较简单

  7. Swift WKWebView的js调用swift

    最近项目需求,需要用到JavaScriptCore和WebKit,但是网上的资源有限,而且比较杂,都是一个博客复制另外一个博客,都没有去实际敲代码验证,下面给大家分享一下我的学习过程。

  8. Swift WKWebView的swift调用js

    不多说,直接上代码:在html里面要添加的的代码,显示swift传过去的参数:这样就实现了swift给js传参数和调用!

  9. 在 Swift 專案中使用 Javascript:編寫一個將 Markdown 轉為 HTML 的編輯器

    你有強烈的好奇心,希望在你的iOS專案中使用JavaScript。jscontext中的所有值都是JSValue對象,JSValue類用於表示任意類型的JavaScript值。因此,我們既需要寫Swift代碼也要寫JavaScript代碼。此外,我們還會在JavaScript中按照這個類的定義來創建一個對象并對其屬性進行賦值。從Swift中呼叫JavaScript就如介紹中所言,JavaScriptCore中最主要的角色就是jscontext類。一個jscontext對象是位於JavaScript環境和本

  10. swift - WKWebView JS 交互

    本文介绍WKWebView怎么与js交互,至于怎么用WKWebView这里就不介绍了HTML代码APP调JS代码结果JS给APP传参数首先注册你需要监听的js方法名2.继承WKScriptMessageHandler并重写userContentController方法,在该方法里接收JS传来的参数3.结果

随机推荐

  1. js中‘!.’是什么意思

  2. Vue如何指定不编译的文件夹和favicon.ico

    这篇文章主要介绍了Vue如何指定不编译的文件夹和favicon.ico,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  3. 基于JavaScript编写一个图片转PDF转换器

    本文为大家介绍了一个简单的 JavaScript 项目,可以将图片转换为 PDF 文件。你可以从本地选择任何一张图片,只需点击一下即可将其转换为 PDF 文件,感兴趣的可以动手尝试一下

  4. jquery点赞功能实现代码 点个赞吧!

    点赞功能很多地方都会出现,如何实现爱心点赞功能,这篇文章主要为大家详细介绍了jquery点赞功能实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  5. AngularJs上传前预览图片的实例代码

    使用AngularJs进行开发,在项目中,经常会遇到上传图片后,需在一旁预览图片内容,怎么实现这样的功能呢?今天小编给大家分享AugularJs上传前预览图片的实现代码,需要的朋友参考下吧

  6. JavaScript面向对象编程入门教程

    这篇文章主要介绍了JavaScript面向对象编程的相关概念,例如类、对象、属性、方法等面向对象的术语,并以实例讲解各种术语的使用,非常好的一篇面向对象入门教程,其它语言也可以参考哦

  7. jQuery中的通配符选择器使用总结

    通配符在控制input标签时相当好用,这里简单进行了jQuery中的通配符选择器使用总结,需要的朋友可以参考下

  8. javascript 动态调整图片尺寸实现代码

    在自己的网站上更新文章时一个比较常见的问题是:文章插图太宽,使整个网页都变形了。如果对每个插图都先进行缩放再插入的话,太麻烦了。

  9. jquery ajaxfileupload异步上传插件

    这篇文章主要为大家详细介绍了jquery ajaxfileupload异步上传插件,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  10. React学习之受控组件与数据共享实例分析

    这篇文章主要介绍了React学习之受控组件与数据共享,结合实例形式分析了React受控组件与组件间数据共享相关原理与使用技巧,需要的朋友可以参考下

返回
顶部