page-scroll-to.uvue 1.4 KB
Newer Older
H
hdx 已提交
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view class="uni-padding-wrap">
      <page-head :title="title"></page-head>
      <button type="default" class="btn-scrollTo" @click="scrollTo">
        scrollTo
      </button>
      <button
        type="default"
        class="btn-scrollToElement"
        @click="scrollToElement"
      >
        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 已提交
24
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26 27
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
H
hdx 已提交
28 29 30
</template>

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

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
61 62 63 64 65
.list-item {
  height: 100px;
  padding-left: 30px;
}
</style>