1.下载 better-scroll
npm install better-scroll --save
2.使用 better-scroll
<template>
<div class="wrapper" ref="wrapper">
<ul class="content">
<li>...</li>
<li>...</li>
...
</ul>
</div>
</template>
<style lang="less" scoped>
.wrapper{
display: fixed;
left: 0;
top: 0;
bottom: 0;
width: 100%;
overflow:hidden;
}
</style>
<script>
import BScroll from 'better-scroll'
mounted () {
this.$nextTick(() => {
if (!this.scroll) {
this.scroll = new BScroll(this.$refs.wrapper, {})
console.log(this.scroll)
}
})
}
</script>
-
快速跳转到指定div
<li @click="cityFast">A</li>
<div ref="A">A</div>
cityFast (e) {
const subtitles = e.target.innerText
const element = this.$refs[subtitles][0]
this.scrooll.scrollToElement(element)
}