微信小程序 进度条 长度根据数字自适应

做的账单每月支出收入和剩余的进度条

之前想了很多复杂的方法 结果这么简单就可以实现大笑

wxml

<view class='top'>
  <view class='topBox'>
    <view class='topLittleBOX-1'>本月收入</view>
    <view class='topLittleBOX-2'>
      <view class='row-1' style='width:{{row1}}rpx'></view>
      <view class='rowText'>{{inmoney}}</view>
    </view>
  </view>
  <view class='topBox'>
    <view class='topLittleBOX-1'>本月支出</view>
    <view class='topLittleBOX-2'>
      <view class='row-2' style='width:{{row2}}rpx'></view>
      <view class='rowText'>{{cost}}</view>
    </view>
  </view>
  <view class='topBox'>
    <view class='topLittleBOX-1'>本月结余</view>
    <view class='topLittleBOX-2'>
      <view class='row-3' style='width:{{row3}}rpx'></view>
      <view class='rowText'>{{little}}</view>
    </view>
  </view>
</view>

wxss

/*top begin  */

.top {
  height: 290rpx;
  background-color: white;
}
.tabbar {
  width: 100%;
  height: 100rpx;
  position: absolute;
  bottom: 0;
  background-color: white;
}
.topBox {
  padding-left: 30rpx;
  padding-top: 50rpx;
  display: flex;
  flex-direction: row;
}
.topLittleBOX-1 {
  font-size: 30rpx;
  color: #4c4c4c;
}
.topLittleBOX-2 {
  padding-left: 50rpx;
  display: flex;
  flex-direction: row;
}
.row-1 {
   width: 305rpx; 
  height: 30rpx;
  background-color: #3edd24;
  border-radius: 20rpx;
}
.row-2 {
   width: 380rpx; 
  height: 30rpx;
  background-color: #dd2446;
  border-radius: 20rpx;
}
.row-3 {
   width: 95rpx; 
  height: 30rpx;
  background-color: #ddc124;
  border-radius: 20rpx;
}
.rowText {
  margin-left: 10rpx;
  font-size: 30rpx;
  color: #4c4c4c;
}

/*top end  */

js(根据最大的数字 取到单位)

大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑大笑

Page({
  data: {
    inmoney: 400.00,
    cost: 1000.00,
    little: -200.00,
    row1: "",
    row2: "",
    row3: "", 
  },
  onLoad: function() {
    var list5 = [this.data.inmoney, this.data.cost, this.data.little];
    var max = Math.max.apply(null, list5 ); 
    console.log(max)
    var unit = 380/max;
    console.log(unit)
  
    this.setData({
      row1: list5[0]*unit,
      row2: list5[1] * unit,
      row3: list5[2] * unit,
    })

  }
})
大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑 大笑
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值