当前位置:网站首页>Two ways for wechat applet to realize dynamic horizontal step bar
Two ways for wechat applet to realize dynamic horizontal step bar
2022-07-28 02:14:00 【Su Su is little Su Su】
1. Realization effect

2. Realization principle
Method 1 :
Total page width :750rpx , Remove the corresponding spacing, etc , Leave a length 600rpx about . When the index of the list is 0 when , Do not display step horizontal lines , That is, the width of each step bar is 600/( Total steps -1)rpx.
flex The horizontal layout , Arrange each element evenly , The width of each element is 100rpx, When there is too much data , Squeeze the element inward .
Method 2 :
progress: Progress bar . The default length unit for component properties is px,2.4.0 Support for incoming units (rpx/px).
take progress Locate in the middle of the picture , By calculating the corresponding proportion , Set the activation percentage .
Set the total width to 600rpx. The length of each serving is 100/( Total steps -1), The percentage is the length of each *( Total number of active steps -1)
eg:
<progress percent="20" show-info stroke-width="3"/>

3. Implementation code
// Method 1 :
<view class="con" wx:for="{
{list}}" wx:key="list" wx:for-item="itemP" wx:for-index="indexP">
<view class="head">
<block wx:for="{
{itemP.stepInfo}}" wx:key='list' wx:for-item="item" wx:for-index="index">
<view class="head_info">
<image class="head_icon" src="{
{item.status==1?itemP.sel_icon:'../img/circle03.png'}}"></image>
<view class="head_title">{
{
item.pro_name}}</view>
<view wx:if="{
{index!=0}}" class='head_line' style="width:{
{600/(itemP.stepInfo.length-1)}}rpx;background:{
{item.status==1?itemP.pro_color:''}};"></view>
</view>
</block>
</view>
</view>
// Method 2 :
<view class="con" wx:for="{
{list}}" wx:key="list" wx:for-item="itemP" wx:for-index="indexP">
<view class="head">
<progress percent="{
{itemP.per}}" stroke-width="2" color="{
{itemP.pro_color}}" />
<block wx:for="{
{itemP.stepInfo}}" wx:key='list' wx:for-item="item" wx:for-index="index">
<view class="head_info">
<image class="head_icon" src="{
{item.status==1?itemP.sel_icon:'../img/circle03.png'}}"></image>
<view class="head_title">{
{
item.pro_name}}</view>
</view>
</block>
</view>
</view>
page {
padding-bottom: 20px;
}
.con {
padding: 24rpx 20rpx;
margin: 20rpx;
background: #FFFFFF;
border-radius: 8rpx;
}
.head {
display: flex;
justify-content: space-between;
position: relative;
}
.head_info {
position: relative;
display: flex;
align-items: center;
flex-direction: column;
width: 100rpx;
text-align: center;
}
.head_icon {
width: 32rpx;
height: 32rpx;
z-index: 1;
}
.head_title {
margin-top: 10rpx;
font-size: 20rpx;
line-height: 28rpx;
color: #333333;
}
.head_line {
position: absolute;
top: 16rpx;
right: 35%;
height: 2rpx;
background: #ccc;
}
progress {
width:600rpx;
position: absolute;
top: 13%;
left: 5%;
}
Page({
data: {
list: [{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
],
sel_icon: "../img/circle02.png",
pro_color: '#3DB969'
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
],
sel_icon: "../img/circle02.png",
pro_color: '#3DB969',
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 0,
pro_name: ' Refund failed '
},
],
sel_icon: "../img/circle02.png",
pro_color: '#3DB969',
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 1,
pro_name: ' Refund failed '
},
{
status: 0,
pro_name: ' Please resubmit your complaint '
},
],
sel_icon: "/img/cart_select.png",
pro_color: '#DE59A3',
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 1,
pro_name: ' Refund failed '
},
{
status: 1,
pro_name: ' Please resubmit your complaint '
},
{
status: 0,
pro_name: ' In appeal '
},
],
sel_icon: "/img/cart_select.png",
pro_color: '#DE59A3',
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 1,
pro_name: ' Refund failed '
},
{
status: 1,
pro_name: ' Please resubmit your complaint '
},
{
status: 1,
pro_name: ' In appeal '
},
{
status: 0,
pro_name: ' The appeal failed '
},
],
sel_icon: "/img/cart_select.png",
pro_color: '#DE59A3',
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 1,
pro_name: ' Refund failed '
},
{
status: 1,
pro_name: ' Please resubmit your complaint '
},
{
status: 1,
pro_name: ' In appeal '
},
{
status: 1,
pro_name: ' The appeal failed '
},
{
status: 0,
pro_name: ' Apply for customer service intervention '
},
],
sel_icon: "/img/wuliu_icon2.png",
pro_color: '#682074'
},
{
stepInfo: [{
status: 1,
pro_name: ' Application for submission '
},
{
status: 1,
pro_name: ' The audit failed '
},
{
status: 1,
pro_name: ' The seller disagrees , No need to return '
},
{
status: 1,
pro_name: ' Refund failed '
},
{
status: 1,
pro_name: ' Please resubmit your complaint '
},
{
status: 1,
pro_name: ' In appeal '
},
{
status: 1,
pro_name: ' The appeal failed '
},
{
status: 1,
pro_name: ' Apply for customer service intervention '
},
{
status: 1,
pro_name: ' Refund successful '
},
],
sel_icon: "/img/wuliu_icon2.png",
pro_color: '#682074'
}
],
},
onShow() {
let {
list
} = this.data;
list.forEach(item => {
let onePer = item.stepInfo.filter(i0 => i0.status == 1).length;
item.per =100/(item.stepInfo.length-1)*(onePer-1)
})
this.setData({
list
})
}
})
4. More applet related , Official account Su Su bug, More applets demo, All in Su Su's code cloud If it helps you , Welcome to star+ subscribe !
边栏推荐
- [database data recovery] data recovery case of insufficient disk space of SQL Server database
- 11-Django-基础篇-数据库操作
- Flex布局学习完成PC端
- Use of classes in typescript
- Hcip 13th day notes
- SkyWalking分布式系统应用程序性能监控工具-中
- Principle and implementation of focal loss
- Interviewer: are you sure redis is a single threaded process?
- Flex布局—固定定位+流式布局—主轴对齐—侧轴对齐—伸缩比
- 轻量版项目管理系统
猜你喜欢

LeetCode 热题 HOT 100 -> 3. 无重复字符的最长子串

Netease cloud copywriting

Completely delete MySQL in Linux system

Uniapp summary (applet)

Common problem types and methods of mathematical univariate differential proof problems in postgraduate entrance examination

Flume(5个demo轻松入门)

记录一次生产死锁

对话Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?

The level "trap" of test / development programmers is not a measure of one-dimensional ability

Appium click operation sorting
随机推荐
Promise from introduction to mastery (Chapter 1 Introduction and basic use of promise)
shell正则和元字符
The petrochemical industry is facing the tide of rising prices, and the digital dealer distribution system platform enables dealers and stores
软件测试面试题:常见的 POST 提交数据方式
Vxe Table/Grid 单元格分组合并
Comparison between hardware SPI and software analog SPI rate
Behind every piece of information you collect, you can't live without TA
Promise从入门到精通(第3章 自定义(手写)Promise)
Likeshop takeout ordering system [100% open source, no encryption]
Packet capturing wizard netcapture app packet capturing tutorial "complete"
小米网站主页面大模块——小模块+导航(浮动案例)
Fluorite network, difficult to be a "lone brave"
ArcGIS: loading historical remote sensing images
Unittest unit test framework full stack knowledge
Unity universal red dot system
Product interpretation - Design and distributed expansion of metersphere UI test module
11-Django-基础篇-数据库操作
软件测试面试题:测试计划工作的目的是什么?测试计划工作的内容都包括什么?其中哪些是最重要的?
mysql创建存储过程---------[HY000][1418] This function has none of DETERMINISTIC, NO SQL
54: Chapter 5: develop admin management services: 7: face warehousing process; Face login process; The browser turns on the video debugging mode (so that the camera can also be turned on in the case o