page-scroll-to.uvue 1.5 KB
Newer Older
H
hdx 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2
  <!-- #ifdef APP -->
3
  <scroll-view style="flex: 1" scroll-with-animation="true">
H
hdx 已提交
4
  <!-- #endif -->
DCloud-WZF's avatar
DCloud-WZF 已提交
5 6 7 8 9
    <view class="uni-padding-wrap">
      <page-head :title="title"></page-head>
      <button type="default" class="btn-scrollTo" @click="scrollTo">
        scrollTo
      </button>
H
hdx 已提交
10
      <button type="default" class="btn-scrollToElement" @click="scrollToElement">
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13 14 15 16 17 18 19
        scrollToElement
      </button>
      <view class="uni-list" v-for="(_, index) in 10" :key="index">
        <view class="uni-list-cell list-item">{{ index }}</view>
      </view>
      <view class="custom-element">scrollTo-custom-element</view>
      <view class="uni-list" v-for="(_, index2) in 10" :key="index2">
        <view class="uni-list-cell list-item">{{ index2 }}</view>
      </view>
H
hdx 已提交
20
    </view>
H
hdx 已提交
21
  <!-- #ifdef APP -->
DCloud-WZF's avatar
DCloud-WZF 已提交
22 23
  </scroll-view>
  <!-- #endif -->
H
hdx 已提交
24 25
</template>

26
<script>
H
hdx 已提交
27 28 29 30 31
  export default {
    data() {
      return {
        title: 'pageScrollTo',
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
32
    },
H
hdx 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    methods: {
      scrollTo() {
        uni.pageScrollTo({
          scrollTop: 100,
          duration: 300,
          success: () => {
            console.log('success')
          },
        })
      },
      scrollToElement() {
        uni.pageScrollTo({
          selector: '.custom-element',
          duration: 300,
          success: () => {
            console.log('success')
          },
        })
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
52
    },
H
hdx 已提交
53
  }
H
hdx 已提交
54 55 56
</script>

<style>
H
hdx 已提交
57 58 59 60
  .list-item {
    height: 100px;
    padding-left: 30px;
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
61
</style>