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
This article example shares the specific code for...
Introduction: The configuration of Docker running...
Today I suddenly thought that the styles of check ...
Effect picture (the border color is too light, pu...
Preface In project development, there are many wa...
In the hive installation directory, enter the con...
Preface: The "Getting Started with MySQL&quo...
Table of contents 1. Introduction 1.1 Principle 1...
This error is often encountered by novices. This ...
Recently, many students have asked me about web p...
There are three date types in MySQL: date(year-mo...
Front-end technology layer (The picture is a bit e...
disabled definition and usage The disabled attrib...
An event is an action performed by the user or th...
I encountered a very unusual parameter garbled pro...