【Kevin Learn 小程序】-->scroll-view

这篇博客详细介绍了小程序中scroll-view组件的使用,包括其效果图展示、属性解析,并给出了具体的代码实例,覆盖了从app.js到scroll-view.json的各项配置。
摘要由CSDN通过智能技术生成

效果图

在这里插入图片描述

属性

参考:scroll-view

实例

  1. app.js
//app.js
App({
  onLaunch: function () {
    console.log('App Launch')
  },
  onShow: function () {
    console.log('App Show')
  },
  onHide: function () {
    console.log('App Hide')
  },
  globalData: {
    hasLogin: false
  }
})
  1. app.json
{
  "pages": [
    "pages/scroll-view/scroll-view"
  ],
  "window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#fff",
    "navigationBarTitleText": "WeChat",
    "navigationBarTextStyle": "black"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}
  1. scroll-view.wxml
<!--scorllview.wxml-->
<view>scroll-view组件</view>
<view class="section">
    <view class="section__title">竖向滚动</view>
    <scroll-view style="height: 200px;" 
        scroll-y
        bindscrolltoupper="upper" 
        bindscrolltolower="lower" 
        bindscroll="scroll" 
        scroll-into-view="{{toView}}"
        scroll-top="{{scrollTop}}" 
        enable-back-to-top="true" 
        scroll-with-animation="true">

        <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="tap">click me to scroll into view </button>
        <button size="mini" bindtap="tapMove">click me to scroll</button>
    </view>
</view>
<view class="section">
    <view class="section__title">横向滚动</view>
    <scroll-view class="scroll-view_H" 
    scroll-x >
        <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>
</view>
  1. scroll-view.wxss
/* pages/scroll-view/scroll-view.wxss */
.scroll-view-item {
    width: 600rpx;
    margin: 0 auto;
    height: 200px;
}
.scroll-view-item.bc_green,
.scroll-view-item_H.bc_green {
    background: green;
}
.scroll-view-item.bc_red,
.scroll-view-item_H.bc_red {
    background: red;
}
.scroll-view-item.bc_yellow,
.scroll-view-item_H.bc_yellow {
    background: yellow;
}
.scroll-view-item.bc_blue,
.scroll-view-item_H.bc_blue {
    background: blue;
}
.scroll-view_H {
    height: 200px;
    margin: 0 auto;
    white-space: nowrap;
}
.scroll-view-item_H{
  display: inline-block;
  width: 100%;
  height: 200px;
}
  1. scroll-view.js
var order = ['red', 'yellow', 'blue', 'green', 'red'];
Page({
  data: {
    toView: 'red',
    scrollTop: 0
  },
  /**
   * scroll-view api
   */
  upper: function (e) {
    console.log(e)
  },
  lower: function (e) {
    console.log(e)
  },
  scroll: function (e) {
    console.log(e)
  },
  tap: function (e) {
    for (var i = 0; i < order.length; ++i) {
      if (order[i] === this.data.toView) {
        this.setData({
          toView: order[i + 1]
        })
        break
      }
    }
  },
  tapMove: function (e) {
    this.setData({
      scrollTop: this.data.scrollTop + 20
    })
  }

})
  1. scroll-view.json
{
  "navigationBarTitleText": "scroll-view 组件"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kevin-Dev

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值