微信小程序-组件-scorllview

1529893754831.jpg

1. 纵向滚动
<!--index.wxml-->
<view class="section__title">vertical scroll</view>
<scroll-view scroll-y style="height: 200px;" bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
<view id="green" class="scroll-view-item bc_green"></view>
<view id="red"  class="scroll-view-item bc_red"></view>
<view id="yellow" class="scroll-view-item bc_yellow"></view>
<view id="blue" class="scroll-view-item bc_blue"></view>
</scroll-view>

<view class="btn-area">
    <button size="mini" bindtap="tapMove">click me to scroll</button>
</view>
<!--index.wxss-->
.page-section{
  margin-bottom: 20rpx;
}
.flex-wrp {display: flex;}
.bc_green {background: green;width:100px; height: 100px;}
.bc_red {background: red;width:100px; height: 100px;}
.bc_blue {background: blue;width:100px; height: 100px;}
.bc_yellow {background: yellow;width:100px; height: 100px;}
<!--index.js-->
Page({
  data: {

  },
  onLoad: function () {
  },
  upper: function (e) {
    console.log(e)
  },
  lower: function (e) {
    console.log(e)
  },
  scroll: function (e) {
    console.log(e)
  },
  tapMove: function (e) {
    this.setData({
      scrollTop: this.data.scrollTop + 10
    })
  }
})
1.gif
  1. 横向滚动
<!--index.wxml-->
<view class="section__title">horizontal scroll</view>
  <scroll-view scroll-x="true" style="white-space: nowrap; display:flex ">
    <view id="green" class="scroll-view-item_H bc_green"></view>
    <view id="red"  class="scroll-view-item_H bc_red"></view>
    <view id="yellow" class="scroll-view-item_H bc_yellow"></view>
    <view id="blue" class="scroll-view-item_H bc_blue"></view>
  </scroll-view>
<!--index.wxss-->
.bc_green {background: green;width:200px; height: 200px;display:inline-block}
.bc_red {background: red;width:200px; height: 200px;display:inline-block}
.bc_blue {background: blue;width:200px; height: 200px;display:inline-block}
.bc_yellow {background: yellow;width:200px; height: 200px;display:inline-block}
.tap_yellow {
1.gif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容