小程序进度条_小程序杂技谈之横向双色进度条

这篇博客介绍如何在小程序中使用view叠加方式创建横向双色进度条,并通过动画实现增长效果。详细讲述了布局、样式定义以及在.js文件中编写进度条增长逻辑的过程。
摘要由CSDN通过智能技术生成
万 圣 节 狂 欢

横向双色进度条

先看效果图

5bb04274ee9c4a8006a609365e77bc7f.gif

e074ad4514db9d57ece302a8662d4150.png

小程序自带的进度条不能满足我们想要的效果,所以这里我们决定用view叠加的方式进行动画增长和展示

3c392a98c8d9e56adc691e97114b0eb6.png 90453b4d866f730c3c609d58b86219b9.gif

编写布局

ae3dc1338870e2da47a4b26d1554b51a.gif bc9d27da60f3bc9111237b78040f3092.png 0dc148a4405fcd42e6e88aec2c00effd.png

    

    style="margin-bottom:{{index == arrProgress.length-1 ? 46 : 0}}rpx;">

      {{item.name}}

      = 100}}">

88dcd3b4aadea2b84fc2f4443eafbc2e.png 90453b4d866f730c3c609d58b86219b9.gif

定义样式

b4557344040877cc6a1e54c6c7640c4d.gif 58124529c0f2d7dddd47a17defa624be.png baece92bc3bdb8809e42996df115b053.png

page{

  background-color: #f5f5f5;

}

.v_white_border{

  margin-top: 200rpx;

  width: 680rpx;

  margin-left: 35rpx;

  border-radius: 20rpx;

  background-color: #ffffff;

  display: flex;

  flex-direction: column;

}

.normal-progress {

  position: relative;

  height: 95rpx;

  width: 600rpx;

  margin-left: 33rpx;

}

.normal-progress-name{

  height:65rpx;

  width: 150rpx;

  margin-top: 10rpx;

  line-height:65rpx;

  font-size:24rpx;

  color:#070A0C;

}

.normal-double-progress {

  width: 600rpx;

  height: 20rpx;

  background-color: #F5F5F5;

  border-radius: 10rpx;

  white-space: nowrap;

}

.normal-progress-1 {

  position: relative;

  float: left;

  height: 20rpx;

  width: 0;

  background-color: #FF8650;

  border-radius: 10rpx;

  overflow: hidden;

}

.normal-progress-2 {

  position: relative;

  height: 20rpx;

  width: 0;

  background-color: #1C80F1;

}

.wh{

  width:100%;

  overflow: hidden;

  border-radius: 40rpx;

}

.iv_give_like {

  position: absolute;

  top: 48rpx;

  right: -14rpx;

  width: 70rpx;

  height: 70rpx;

  opacity: 0;

}

4be7d117e7b80d7b851dc9ab6fd4a5b5.png 512612d7d398b0c0e8d7d0d5170d97f0.gif

编写逻辑

a9b38ffad5a776f0908836950bf4e600.gif 69f791b96af158685b9cbe156cf8d52c.png a956c712e0e03b8b1d186525c8b40c8f.png

我们在.js文件中编写进度条增长动画逻辑

/**

   * 页面的初始数据

   */

  data: {

    arrProgress: [

      {

        "name": "展示",

        "animation1": {},

        "animation2": {},

        "animation3": {}

      },

      {

        "name": "展示",

        "animation1": {},

        "animation2": {},

        "animation3": {}

      },

      {

        "name": "展示",

        "animation1": {},

        "animation2": {},

        "animation3": {}

      },

      {

        "name": "展示",

        "animation1": {},

        "animation2": {},

        "animation3": {}

      }

    ],

    arrPre1 : [50,40,60,100],

    arrPre2 : [80,60,70,100]

  },

上面初始化了5个进度条并定义了最终的长度

然后在onLoad中进行监听页面加载

/**

   * 生命周期函数--监听页面加载

   */

  onLoad: function (options) {

    this.progress2Animation(this.data.arrPre1, this.data.arrPre2)

  },

这里是主要的逻辑,创建动画createAnimation,并给数组每一个添加动画,计算width的长度并定义增长的时间,最后当到达100时则展示最终动效

progress2Animation: function (arrPre1, arrPre2) {

    var arrNew = [];

    for (var i = 0; i 

      var pre1 = arrPre1[i];

      var animation1 = wx.createAnimation({

        duration: 500

      })

      var animation2 = wx.createAnimation({

        duration: 500

      })

      var animation3 = wx.createAnimation({

        duration: 500

      })

      if(pre1 > 100){

        pre1 = 100

      }

      animation1.width(pre1 * 6 + 'rpx').step();

      animation2.width(pre1 * 6 + 'rpx').step();

      animation3.translateX(pre1 * 6 + 'rpx').step();

      var oldProgress = this.data.arrProgress[i];

      oldProgress.animation1 = animation1.export();

      oldProgress.animation2 = animation2.export();

      oldProgress.animation3 = animation3.export();

      arrNew.push(oldProgress)

    }

    this.setData({

      arrProgress: arrNew,

    });

    var blockThis = this;

    setTimeout(()=>{

      blockThis.animate('.iv_give_like', [

        { opacity: 1, scale: [0.9, 0.9] },

        { opacity: 1, scale: [1.2, 1.2] },

        { opacity: 1, scale: [1, 1] },

        { opacity: 1, scale: [1.1, 1.1] },

        { opacity: 1, scale: [1, 1] }

        ],400, function() {

        }.bind(blockThis))

    },600)

    setTimeout(function () {

      arrNew = [];

      for (var i = 0; i 

        var pre2 = arrPre2[i];

        var animation1 = wx.createAnimation({

          duration: 500

        })

        var animation3 = wx.createAnimation({

          duration: 500

        })

        if(pre2 > 100){

          pre2 = 100

        }

        animation1.width(pre2 * 6 + 'rpx').step();

        animation3.translateX(pre2 * 6 + 'rpx').step();

        var oldProgress = blockThis.data.arrProgress[i];

        oldProgress.animation1 = animation1.export();

        oldProgress.animation3 = animation3.export();

        arrNew.push(oldProgress)

      }

      blockThis.setData({

        arrProgress: arrNew

      })

    }, 500)

  },

9860fdd390e04c1fb30a7995ef57efd5.png b3946257105f792bcd179428d9eccbbb.png ab2e77c78f10ab1a9d417b6cce619ad5.png 84e47039fb53e60e114098103a81b461.png

这样效果就完成了

c401b434fd5c3d07e7fcb5488b3b801f.png 764e9a8c220b4cbc01cd27f399015473.png 9970a98781bb3639a6eb89ca083f1df4.png b0f80dc8c7f84568d860ab697f87c224.png 1d854328fd23c0f0d722e792c1758965.png cf4fcc3e741f1b441c9b0e073d887c52.png

万圣节又叫诸圣节,在每年的11月1日,是西方的传统节日;而万圣节前夜的10月31日是这个节日最热闹的时刻。在中文里,常常把万圣节前夜

7905e71e6bde65a4ea54073f9891da98.png 63482129c75f369cf3b18095f395d8b8.png 57bb11c67e70738acfbbf553884e4052.png 4092faf0cc08f125d76dfc8e1619680c.png dd3f6b35ec578fdfa79ce8c939bab6f4.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值