首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ JavaScript / 文章详情

使用better-scroll完成自动滚动

Sonder
2023-03-23
1176字
3分钟
浏览 (1.7k)

👉👉👉封装的组件地址

效果图

222311.gif
复制代码
<template>
  <div class='www'>
    <BetterScroll ref='ItemScroll'>
      <div v-for='item in 100'>{{item}}</div>
    </BetterScroll>
  </div>
</template>

<script>
import BetterScroll from '@/components/BetterScroll'

export default {
  components: {
    BetterScroll
  },
  async mounted() {
    await this.initScroll()
    this.runScroll();
  },
  methods: {
    initScroll(){
      return new Promise(resolve => {
        this.$refs.ItemScroll && this.$refs.ItemScroll.initScroll()
        resolve()
      })
    },
    runScroll() {
      let maxScrollHeight = this.$refs.ItemScroll.getScrollAttr("maxScrollY");
      let time = Math.ceil(Math.abs(maxScrollHeight) / 60) * 5;
      setTimeout(() => {
        this.$refs.ItemScroll &&
        this.$refs.ItemScroll.scrollTo(maxScrollHeight, time * 1000);
      }, 1000);
    },
  }
}
</script>

<style lang="scss" scoped>
.www {
  height: 100px;
  text-align: center;
  user-select: none;
  background: #1f2d3d;
  color: #fff;
  overflow: hidden;
}
</style>
下一篇 / Vue中@click.stop与@click.prevent、@click.native

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)