‘backBox'是外层容器类名, 根据传入的index,定位在不同的位置

组件:

<template>
  <div class="toTop" @click="getActiveClass(0)">
      <img src="@/assets/images/up01.png" alt="">
  </div>
</template>

<script>
  export default {
    methods: {
      getActiveClass(index) {
        let jump = document.querySelectorAll('.backBox')
        jump[index].scrollIntoView({ block: 'start', behavior: 'smooth' })
      }
    }
  }
</script>

<style lang="less" scoped>
  .toTop {
      position: fixed;
      bottom: 60px;
      right: 20px;
      width:48px;
      height:48px;
      img {
        width: 48px;
        height: 48px;
      }
  }
</style>

 

posted on 2020-07-14 16:55  丶小馨  阅读(401)  评论(0编辑  收藏  举报