scroll-view.uvue 4.7 KB
Newer Older
Y
init  
yurj26 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
Y
init  
yurj26 已提交
5
    <view>
DCloud-WZF's avatar
DCloud-WZF 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
      <page-head title="scroll-view,区域滚动视图"></page-head>
      <view class="uni-padding-wrap uni-common-mt">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text">Vertical Scroll</text>
          <text class="uni-subtitle-text">纵向滚动</text>
        </view>
        <view>
          <scroll-view
            :scrollTop="scrollTop"
            :scrollY="true"
            class="scroll-Y"
            scroll-with-animation="true"
            @scrolltoupper="upper"
            @scrolltolower="lower"
            @scroll="scroll"
          >
            <view id="demo1" class="scroll-view-item uni-bg-red"
              ><text class="text">A</text></view
            >
            <view id="demo2" class="scroll-view-item uni-bg-green"
              ><text class="text">B</text></view
            >
            <view id="demo3" class="scroll-view-item uni-bg-blue"
              ><text class="text">C</text></view
            >
          </scroll-view>
        </view>
        <view @tap="goTop" class="uni-center uni-common-mt">
          <text class="uni-link">点击这里返回顶部</text>
        </view>
Y
init  
yurj26 已提交
36

DCloud-WZF's avatar
DCloud-WZF 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        <view class="uni-title uni-common-mt">
          <text class="uni-subtitle-text">下拉刷新</text>
        </view>
        <button
          type="primary"
          class="button default-button"
          @click="gotoRefresher"
        >
          跳转"下拉刷新示例"
        </button>

        <view class="uni-title uni-common-mt">
          <text class="uni-title-text">Horizontal Scroll</text>
          <text class="uni-subtitle-text">横向滚动</text>
        </view>
        <view>
          <scroll-view
            class="scroll-view_H"
            :scrollX="true"
            @scroll="scroll"
            :scrollLeft="120"
          >
            <view id="demo1" class="scroll-view-item_H uni-bg-red"
              ><text class="text">A</text></view
            >
            <view id="demo2" class="scroll-view-item_H uni-bg-green"
              ><text class="text">B</text></view
            >
            <view id="demo3" class="scroll-view-item_H uni-bg-blue"
              ><text class="text">C</text></view
            >
          </scroll-view>
Y
init  
yurj26 已提交
69
        </view>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
70 71 72 73 74 75
        
		<button
		  type="primary"
		  class="button default-button"
		  @click="moreProps"
		>
76
		  非下拉刷新的属性示例
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
77 78 79
		</button>
		<view class="uni-common-pb"></view>
		<button type="primary" class="button default-button" @click="jumpToRefresher">
80 81 82 83 84
			下拉刷新的属性示例
		</button>
		<view class="uni-common-pb"></view>
		<button type="primary" class="button default-button" @click="jumpToCustomRefresher">
			自定义下拉刷新的属性示例
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
85 86
		</button>
		<view class="uni-common-pb"></view>
DCloud-WZF's avatar
DCloud-WZF 已提交
87
      </view>
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
88
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
89 90 91
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
Y
init  
yurj26 已提交
92 93
</template>
<script lang="ts">
DCloud-WZF's avatar
DCloud-WZF 已提交
94 95 96 97 98 99 100
import ScrollToLowerEvent from 'io.dcloud.uniapp.runtime.ScrollToLowerEvent'
import ScrollToUpperEvent from 'io.dcloud.uniapp.runtime.ScrollToUpperEvent'
export default {
  data() {
    return {
      scrollTop: 0,
      oldScrollTop: 0,
Y
init  
yurj26 已提交
101
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  },
  methods: {
    upper: function (e: ScrollToUpperEvent) {
      console.log(e)
    },
    lower: function (e: ScrollToLowerEvent) {
      console.log(e)
    },
    scroll: function (e: ScrollEvent) {
      this.oldScrollTop = e.detail.scrollTop
    },
    goTop: function () {
      // 解决view层不同步的问题
      this.scrollTop = this.oldScrollTop
      this.$nextTick(function () {
        this.scrollTop = 0
      })
      uni.showToast({
        icon: 'none',
        title: '纵向滚动 scrollTop 值已被修改为 0',
      })
    },
    gotoRefresher: function () {
      uni.navigateTo({
        url: '/pages/component/scroll-view/scroll-view-refresher',
      })
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
128 129 130 131 132 133 134 135 136 137
    },
	moreProps(){
		uni.navigateTo({
		  url: '/pages/component/scroll-view/scroll-view-props',
		})
	},
	jumpToRefresher() {
		uni.navigateTo({
		  url: '/pages/component/scroll-view/scroll-view-refresher-props',
		})
138 139 140 141 142 143
	},
	jumpToCustomRefresher() {
		uni.navigateTo({
		  url: '/pages/component/scroll-view/scroll-view-custom-refresher-props',
		})
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
144 145
  },
}
Y
init  
yurj26 已提交
146 147 148
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
149 150 151
.scroll-Y {
  height: 300rpx;
}
Y
init  
yurj26 已提交
152

DCloud-WZF's avatar
DCloud-WZF 已提交
153 154 155 156
.scroll-view_H {
  width: 100%;
  flex-direction: row;
}
Y
init  
yurj26 已提交
157

DCloud-WZF's avatar
DCloud-WZF 已提交
158 159 160 161 162
.scroll-view-item {
  height: 300rpx;
  justify-content: center;
  align-items: center;
}
Y
init  
yurj26 已提交
163

DCloud-WZF's avatar
DCloud-WZF 已提交
164 165 166 167 168 169
.scroll-view-item_H {
  width: 690rpx;
  height: 300rpx;
  justify-content: center;
  align-items: center;
}
Y
init  
yurj26 已提交
170

DCloud-WZF's avatar
DCloud-WZF 已提交
171 172 173 174 175 176 177 178
.text {
  font-size: 36rpx;
  color: #ffffff;
}
.button {
  margin-top: 30rpx;
}
</style>