scroll-view cannot scroll the problem

Prepare

<!--index.wxml-->
<view class="container">
<scroll-view class="scroll-container">
  <view class="scroll-item" wx:key="index"  wx:for="{
     
     {listData}}">
    {
   
   {item}}
  </view>
</scroll-view>
</view>

js

// index.js
Page({
    
    
  data:{
    
    
    listData:[
      "小明01",
      "小明02",
      "小明03",
      "小明04",
      "小明05",
      "小明06",
      "小明07",
      "小明08",
      "小明09",
      "小明10"
    ]
  }
})

insert image description here

  1. Determine the sliding direction you want to achieve, and check whether scroll-x or scroll-y is written (scroll-x: true supports horizontal sliding scroll-y: true supports vertical sliding)
  2. Check if you haven’t set a fixed height for the scroll-view. I didn’t set a fixed height before and couldn’t slide (note that the set height should not exceed the height of the parent container, otherwise if the height is too high, the scroll-view won’t be able to slide. Because the layout is displayed, but the height of the parent container is not enough and it is not displayed)

modify style

/**index.wxss**/
.scroll-container{
    
    
  width: 700rpx;
  height: 40rpx;
  line-height: 40rpx;
  white-space: nowrap;
}

.scroll-container .scroll-item{
    
    
  display: inline-block;
}

Allow scroll-view to be horizontal

<!--index.wxml-->
<view class="container">
<scroll-view scroll-x="true" class="scroll-container">
  <view class="scroll-item" wx:key="index"  wx:for="{
     
     {listData}}">
    {
   
   {item}}
  </view>
</scroll-view>
</view>

You can achieve the scrolling effect
insert image description here

Guess you like

Origin blog.csdn.net/qq_36437991/article/details/129990334