小程序scroll-view滑动进度条

 

效果图如下:

 

 

 

 代码如下:

复制代码
Page({
    data: {
    left:0.5  // 初始化滑块位置
    },
      //金刚区滑动事件
    scroll(event){
      let scrollLeft = event.detail.scrollLeft + 301;
      let scrllWidth = event.detail.scrollWidth;
      let left;
      if(scrollLeft < (scrllWidth/2)){
        left = `50%`
      }else{
        left = `${(scrollLeft) / scrllWidth * 100}%`
      }
      this.setData({
        left, //模拟滑块滑动 根据css设置 距离左边的百分比
      })
    },
    })
复制代码

HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<view class="content">
    <view class="block">
            <view class="be-center fubi-block">
                <view class="block-title-left">
                    <text>优惠券</text>
                </view>
                <view bindtap='skipPage' data-url="/pages/coupons/index">
                    <view class="block-title-right">
                        <view class="more">更多</view>
                        <van-icon class="v-center" name="arrow" />
                    </view>
                </view>
            </view>
            <view class="coupon-module">
                <scroll-view  scroll-x bindscroll="scroll">
                    <view class="coupon-list">
                        <view class="couponsItem" wx:for="{{10}}" >
                            <view class="block-coupons">
                                <view class="onelist-hidden coupons-fc">
                                    <view class="coupons-je">
                                        <text class="amount">¥100</text>
                                    </view>
                                    <view class="onelist-hidden f-20" style="text-align: center;">
                                        <text>满任意金额可用</text>
                                    </view>
                                </view>
                                <view class="twolist-hidden coupons-name">优惠券名称</view>
                            </view>
                            <view class="coupons-btn">
                                去使用
                            </view>
                        </view>
                    </view
                </scroll-view>
                <!-- 模拟进度条 -->
            <view class="slider">
            <view class="slider-inside slider-inside-location" style="left:{{left}}"></view>
            </view>
            </view>
    </view>
</view>

  css部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* 垂直居中 */
.content{
    background:#F5F5F5;
    height: 100vh;
}
.v-center {
    display: flex;
    align-items: center;
  }
.be-center {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
.block {
    padding: 0 24rpx;
}
 
.fubi-block {
    height: 62rpx;
    line-height: 62rpx;
}
 
.block-title-left {
    font-size: 32rpx;
    font-weight: 500;
}
 
.block-title-fubi {
    width: 42rpx;
    height: 45rpx;
    vertical-align: text-bottom;
}
 
.block-title-right {
    color: #999;
    font-size: 24rpx;
    display: flex;
    align-items: center;
}
 
.block-title-right .more {
    margin-right: 4rpx;
}
 
/* .block-title-right .v-center {
    margin-right: -8rpx;
} */
 
.card-block {
    margin-top: 24rpx;
    margin-bottom: 40rpx;
    width: 702rpx;
    border-radius: 16rpx;
    background: rgba(255, 255, 255, 1);
}
.coupon-list {
    padding: 32rpx 0 24rpx;
    /* height: 288rpx; */
    /* display: flex; */
}
 
.couponsItem {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 16rpx;
    height: 248rpx;
}
 
.block-coupons {
    width: 194rpx;
    height: 184rpx;
    background: url('https://fsk-oss.oss-cn-shanghai.aliyuncs.com/image/c49d1185-b28b-491e-8b7b-87766a6e8788%E4%BC%98%E6%83%A0%E5%88%B8.png') no-repeat;
    background-size: 100% 100%;
    margin-bottom: 12rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.coupons-fc {
    color: rgba(235, 88, 56, 1);
    width: 162rpx;
    height: 96rpx;
}
 
.coupons-name {
    color: rgba(255, 255, 255, 1);
    font-size: 24rpx;
    font-weight: 500;
    width: 162rpx;
    height: 56rpx;
    line-height: 28rpx;
    text-align: center;
    margin-top: 20rpx;
    margin-bottom: 12rpx;
}
 
.coupons-je {
    text-align: center;
    height: 67rpx;
    line-height: 67rpx;
}
 
.amount {
    font-size: 48rpx;
    font-weight: 500;
}
.coupons-btn {
    width: 140rpx;
    height: 52rpx;
    line-height: 52rpx;
    border-radius: 16rpx;
    background: linear-gradient(89.8deg, rgba(243, 128, 53, 1) 0%, rgba(241, 109, 50, 1) 100%);
    color: #fff;
    text-align: center;
}
.coupon-content{
    display: flex;
}
.coupon-list .couponsItem:nth-child(1) {
    margin-left: 24rpx;
}
 
.coupon-module {
    background: #ffffff;
    border-radius: 16rpx;
    position: relative;
    height: 342rpx;
    width: 702rpx;
    overflow: hidden;
    margin-top: 24rpx;
    margin-bottom: 40rpx;
}
 
.coupon-list {
    padding: 32rpx 0 24rpx;
    display: flex;
}
 
 
.slider {
    position: absolute;
    bottom: 24rpx;
    left: 50%;
    transform: translateX(-50%);
    width: 60rpx;
    height: 6rpx;
    border-radius: 4rpx;
    background: linear-gradient(135deg, rgba(247, 153, 82, 0.3) 0%, rgba(245, 115, 93, 0.3) 57.99999999999999%, rgba(244, 108, 180, 0.3) 100%);
}
 
.slider-inside {
    transform: translateX(-100%);
    width: 30rpx;
    height: 100%;
    border-radius: 4rpx;
    background: linear-gradient(135deg, rgba(247, 153, 82, 1) 0%, rgba(245, 115, 93, 1) 57.99999999999999%, rgba(244, 108, 180, 1) 100%);
}
  /* 滑块滑动模拟 */
  .slider-inside-location {
    position: absolute;
    left: 50%;
  }
  /* scroll-view {
    white-space: nowrap;
  } */
  /* 去除滚动条 */
  ::-webkit-scrollbar {
    display:none;
    width:0;
    height:0;
    color:transparent;
  }

  

posted @   不特别但唯一  阅读(329)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示