小程序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 : 100 vh; } .v- center { display : flex; align-items: center ; } .be- center { display : flex; justify- content : space-between; align-items: center ; } . block { padding : 0 24 rpx; } .fubi- block { height : 62 rpx; line-height : 62 rpx; } .block-title- left { font-size : 32 rpx; font-weight : 500 ; } .block-title-fubi { width : 42 rpx; height : 45 rpx; vertical-align : text-bottom ; } .block-title- right { color : #999 ; font-size : 24 rpx; display : flex; align-items: center ; } .block-title- right .more { margin-right : 4 rpx; } /* .block-title-right .v-center { margin-right: -8rpx; } */ .card- block { margin-top : 24 rpx; margin-bottom : 40 rpx; width : 702 rpx; border-radius: 16 rpx; background : rgba( 255 , 255 , 255 , 1 ); } .coupon-list { padding : 32 rpx 0 24 rpx; /* height: 288rpx; */ /* display: flex; */ } .couponsItem { display : flex; flex- direction : column; align-items: center ; margin-right : 16 rpx; height : 248 rpx; } .block-coupons { width : 194 rpx; height : 184 rpx; 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 : 12 rpx; display : flex; flex- direction : column; align-items: center ; } .coupons-fc { color : rgba( 235 , 88 , 56 , 1 ); width : 162 rpx; height : 96 rpx; } .coupons-name { color : rgba( 255 , 255 , 255 , 1 ); font-size : 24 rpx; font-weight : 500 ; width : 162 rpx; height : 56 rpx; line-height : 28 rpx; text-align : center ; margin-top : 20 rpx; margin-bottom : 12 rpx; } .coupons-je { text-align : center ; height : 67 rpx; line-height : 67 rpx; } .amount { font-size : 48 rpx; font-weight : 500 ; } .coupons-btn { width : 140 rpx; height : 52 rpx; line-height : 52 rpx; border-radius: 16 rpx; background : linear-gradient( 89.8 deg, 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 : 24 rpx; } .coupon-module { background : #ffffff ; border-radius: 16 rpx; position : relative ; height : 342 rpx; width : 702 rpx; overflow : hidden ; margin-top : 24 rpx; margin-bottom : 40 rpx; } .coupon-list { padding : 32 rpx 0 24 rpx; display : flex; } .slider { position : absolute ; bottom : 24 rpx; left : 50% ; transform: translateX( -50% ); width : 60 rpx; height : 6 rpx; border-radius: 4 rpx; background : linear-gradient( 135 deg, 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 : 30 rpx; height : 100% ; border-radius: 4 rpx; background : linear-gradient( 135 deg, 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 ; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了