Mini Program Custom Scroll-View Scroll Bar Without further ado, here are the renderings Rendering wxml code <scroll-view scroll-x class="scroll-view" bindscroll="bindScroll"> <block wx:for="{{arr}}" wx:key="index"> <view class="scroll-item">scroll-view{{index}}</view> </block> </scroll-view> <!-- Scrollbar --> <view class="slide"> <view class='slide-bar'> <view class="slide-action" style="width:{{slideWidth}}rpx; margin-left:{{slideLeft<=1 ? 0 : slideLeft+'rpx'}};"> </view> </view> </view> wxss code page{ height: 100vh; background: rgb(111, 80, 65) } .scroll-view{ display: flex; width: 100%; white-space: nowrap; padding-top: 20rpx; } .scroll-item:nth-child(1){ margin-left: 40rpx; } .scroll-item { display: inline-block; width: 550rpx; height: 463rpx; background: rgba(199, 180, 165); border-radius: 20rpx; margin-right: 30rpx; color: #fff; } .slide{ background:rgb(111, 80, 65); width:100%; padding-top:20rpx; } .slide .slide-bar{ width:180rpx; margin:0 auto; height: 4rpx; background: rgba(255,255,255,.2); } .slide .slide-bar .slide-action{ height:100%; background:#fff; } js code /** * Initial data of the page */ data: { arr: 10, slideWidth: '', slideLeft: '' }, /** * Life cycle function--listen for page loading*/ onLoad: function (options) { // Calculate the ratio this.calcRatio(); }, /** * Calculate the ratio */ calcRatio() { var windowWidth = wx.getSystemInfoSync().windowWidth; // Calculate the total length of the list var totalLength = (this.data.arr * 580) + 40; // Calculate the ratio of the slider var slideRatio = 180 / totalLength * (750 / windowWidth); /** * Total screen length / total list length = ratio of slider to scroll bar length * ratio of slider to scroll bar length * length of scroll list = width of slider */ var sliderWidth = 750 / totalLength * 180; this.setData({ slideWidth: sliderWidth, totalLength: totalLength, slideRatio: slideRatio }) }, /** * Monitor scrolling */ bindScroll(e) { this.setData({ slideLeft: e.detail.scrollLeft * this.data.slideRatio }) }, Appendix: scroll-view scrollable view area Summarize This is the end of this article about WeChat mini-program custom scroll-view. For more relevant WeChat mini-program custom scroll-view content, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed steps for quick installation of openshift
>>: Summary of common problems in downloading and installing MySQL 5.7 on Win7 64-bit
HTML img produces an ugly blue border after addin...
I was recently working on a comment feature that ...
Achieve resultsImplementation Code html <div&g...
Detailed explanation of the implementation method...
Table of contents Uninstall and install samba Cre...
This article shares the specific code for randomi...
Table of contents Business requirements: Solution...
What is keepalive? In normal development, some co...
Here is an example code for using regular express...
Table of contents 1. Install Docker 2. Install so...
This article shares the specific code of js to im...
Problem Description I want to use CSS to achieve ...
1. Inline reference: used directly on the label, ...
1. What is master-slave replication? The DDL and ...
The docker image id is unique and can physically ...