| item | desc |
|---|---|
| scroll-x | 允许横向滚动;最好也显式指定宽度;谨慎使用 % 宽度 |
| scroll-y | 允许纵向滚动;应显式指定高度 |
| scroll-into-view | 滚动到值为 id 的某子元素;id 不能以数字开头 |
| scroll-with-animation | 使用动画过渡 |
| scroll-top | 设置竖向滚动条位置 |
| bindscroll | 滚动时触发 |
| item | desc |
|---|---|
| enable-flex | 布尔;默认false
水平方向启用 flexbox 布局,使之成为 flex 容器!!! |
| using-sticky | 布尔;默认false
启用 position: sticky 特性 |
| item | desc |
|---|---|
| type |
渲染模式
list:列表模式;默认
custom:自定义模式; 子组件是sticky-section、list-view或grid-view
nested:嵌套模式
|
| using-sticky | 布尔;默认false;启用 position: sticky 特性 |
<scroll-view scroll-x class="wrap">
<view class="inner-wrap">
<view class="item">item1</view>
...
<view class="item">item10</view>
</view>
</scroll-view>
.inner-wrap{
display: flex;
gap: 40rpx;
}
.item{
width: 100rpx;
height: 100rpx;
flex-shrink: 0;
}
<scroll-view scroll-x enable-flex class="wrap">
<view class="item">item1</view>
...
<view class="item">item10</view>
</scroll-view>
.wrap{
white-space: nowrap;
}
.item{
display: inline-block;
}
<scroll-view scroll-y using-sticky class="sc"></scroll-view>
<scroll-view scroll-x scroll-with-animation scroll-into-view="nav{{curIndex}}">
<view class="nav flex">
<view class="item {{index==curIndex?'active':''}}"
wx:for="{{navs}}" wx:key="index"
data-ind="{{index}}"
id="nav{{index}}"
bind:tap="selectItem">
{{item.title}}
</view>
</view>
</scroll-view>
<swiper current="{{curIndex}}" bindchange="changeItem" circular>
<swiper-item class="swiper-item" wx:for="{{swipers}}" wx:key="index">
{{item}}
</swiper-item>
</swiper>
selectItem(e:any) {
this.setData({
curIndex: e.target.dataset.ind
})
},
changeItem(e:any){
this.setData({
curIndex: e.detail.current
})
}