微信小程序-进度条-刻度
Posted 记录-分享
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了微信小程序-进度条-刻度相关的知识,希望对你有一定的参考价值。
js
var app = getApp()
Page({
data: {
num:8,//这是当前有几个人
jindutiao: [ //这个是进度条的标准,刻度
{
num:3,
price:\'999\'
},
{
num: 5,
price: \'799\'
},
{
num: 10,
price: \'599\'
}
],
},
onLoad:function(){
this.jindutiao();
},
jindutiao: function () {
var that = this;
var jindutiao = that.data.jindutiao;
var num = that.data.num;
var p = 0;
for (var i = 0; i < jindutiao.length; i++) {
if (jindutiao[i].num > num) {
p = i;
break;
}
}
if (i == jindutiao.length) { p = i; }
for (var j = 0; j < p; j++) {
jindutiao[j].statu = true;
}
if (p == 0) {
num = 0.5 / jindutiao.length * 100;
} else if (jindutiao[p - 1].num < num) {
num = (p + 0.5) / jindutiao.length * 100;
//毕竟不是当前进度等分,所以让他在等于8,7,6的时候也能在中间。就加0.5
} else {
num = p / jindutiao.length * 100;
//当前黄色进度长度就是当前人数除以总人数乘以100,就是进度条宽度的百分比。
}
that.setData({
width: num,
p: p,
jindutiao: jindutiao
})
},
})
CSS
<view class="bigs1" >
<view class=\'hui\'>
<block wx:for="{{jindutiao}}">
<view class=\'viewsmall\'></view>
<view class="zhongJianSelect"wx:if="{{item.statu}}"></view>
<view class="zhongJian"wx:else></view>
</block>
</view>
<!--刻度杠 -->
<view class=\'kedudian\'style="left:{{width-11}}%">
<image mode=\'scaleToFill\' src=\'../img/dialog.png\' class=\'jinduPng\'></image>
<text class=\'cantuanNumber\'>{{num}}人已参团</text>
</view>
<view class=\'huang\' style="width:{{width}}%"></view>
</view>
<view class=\'bigs2\'>
<view class=\'viewbig\'>
<block wx:for="{{jindutiao}}">
<view class=\'viewsmall2\' wx:if="{{item.statu}}">
<text class=\'viewsmall2Text\'>{{item.num}}人团</text>
<text class=\'viewsmall2Text\'>¥{{item.price}}</text>
</view>
<view class=\'viewsmall2\' wx:else>
<text class=\'viewsmall2Text viewsmall2TextSelect\'>{{item.num}}人团</text>
<text class=\'viewsmall2Text viewsmall2TextSelect\'>¥{{item.price}}</text>
</view>
</block>
</view>
wxml
<view class="bigs1" >
<view class=\'hui\'>
<block wx:for="{{jindutiao}}">
<view class=\'viewsmall\'></view>
<view class="zhongJianSelect"wx:if="{{item.statu}}"></view>
<view class="zhongJian"wx:else></view>
</block>
</view>
<!--刻度杠 -->
<view class=\'kedudian\'style="left:{{width-11}}%">
<image mode=\'scaleToFill\' src=\'../img/dialog.png\' class=\'jinduPng\'></image>
<text class=\'cantuanNumber\'>{{num}}人已参团</text>
</view>
<view class=\'huang\' style="width:{{width}}%"></view>
</view>
<view class=\'bigs2\'>
<view class=\'viewbig\'>
<block wx:for="{{jindutiao}}">
<view class=\'viewsmall2\' wx:if="{{item.statu}}">
<text class=\'viewsmall2Text\'>{{item.num}}人团</text>
<text class=\'viewsmall2Text\'>¥{{item.price}}</text>
</view>
<view class=\'viewsmall2\' wx:else>
<text class=\'viewsmall2Text viewsmall2TextSelect\'>{{item.num}}人团</text>
<text class=\'viewsmall2Text viewsmall2TextSelect\'>¥{{item.price}}</text>
</view>
</block>
</view>
转载 https://blog.csdn.net/qq_34622811/article/details/80900361
以上是关于微信小程序-进度条-刻度的主要内容,如果未能解决你的问题,请参考以下文章