Former-commit-id: 61b3ce81f703f3b83d29c7ec9f1f58ac351e9feb [formerly 85631772690b91e0d39e1b9e90d23dae7d929c9a] [formerly 61b3ce81f703f3b83d29c7ec9f1f58ac351e9feb [formerly 85631772690b91e0d39e1b9e90d23dae7d929c9a] [formerly 61b3ce81f703f3b83d29c7ec9f1f58ac351e9feb [formerly 85631772690b91e0d39e1b9e90d23dae7d929c9a] [formerly 85631772690b91e0d39e1b9e90d23dae7d929c9a [formerly 8194f7e92144427b7c4947a93812a1cd0564a642 [formerly f4b7b47afbed6f98890de3ee269cbeae522f819e]]]]] Former-commit-id: ea4bebdc76ac4332d037f141867abe2d88211643 Former-commit-id: 2be71d915c7aca35f87f3cd91b313a4e1d92fdc5 Former-commit-id: cf55d88b39e1f3293deada0f7294e9938a15667b [formerly 19d9709c2a3c71a1a4cf268f80ebcaff05a6c97d] Former-commit-id: e8c7b6443a38f5d4311d19a8ecf9d5a65a5e3cd2 Former-commit-id: c68ed1fe39857770bef0feb198d6c8ab55a97959 Former-commit-id: cad71a8eb5306a6303be52cd6eed4021c16c93b6 Former-commit-id: 22d6241afd1762a0f999c89dcb24052504660e82 Former-commit-id: 3a183f17d724638f25c5f5ea70a368cdc3cd4f85
106 lines
2.7 KiB
Vue
106 lines
2.7 KiB
Vue
<template>
|
|
<d2-container :filename="filename">
|
|
<template slot="header">滚动定位</template>
|
|
<el-row :gutter="20">
|
|
<el-col :span="8">
|
|
<div ref="wrapper" class="demo-bs-wrapper">
|
|
<div>
|
|
<div v-for="n in 100" :key="n" class="demo-bs-item" :id="`demo-bs-item-${n}`">n : {{n}}</div>
|
|
</div>
|
|
</div>
|
|
</el-col>
|
|
<el-col :span="16">
|
|
<div class="d2-mb">
|
|
<p>滚动时间 ms</p>
|
|
<el-slider v-model="time" :min="100" :max="3000"></el-slider>
|
|
</div>
|
|
<div class="d2-mb">
|
|
<el-button-group>
|
|
<el-button @click="handleScrollTo(100)">滚动到100像素位置</el-button>
|
|
<el-button @click="handleScrollTo(300)">滚动到300像素位置</el-button>
|
|
</el-button-group>
|
|
</div>
|
|
<div class="d2-mb">
|
|
<el-button-group>
|
|
<el-button @click="handleScrollBy(50)">向下滚动50像素</el-button>
|
|
<el-button @click="handleScrollBy(-50)">向上滚动50像素</el-button>
|
|
</el-button-group>
|
|
</div>
|
|
<div class="d2-mb">
|
|
<el-button-group>
|
|
<el-button @click="handleScrollToElement(4)">滚动到第四个</el-button>
|
|
<el-button @click="handleScrollToElement(14)">滚动到第十四个</el-button>
|
|
<el-button @click="handleScrollToElement(24)">滚动到第二十四个</el-button>
|
|
</el-button-group>
|
|
</div>
|
|
</el-col>
|
|
</el-row>
|
|
<template slot="footer">
|
|
<d2-link-btn title="文档" link="http://ustbhuangyi.github.io/better-scroll/doc/zh-hans/"/>
|
|
</template>
|
|
</d2-container>
|
|
</template>
|
|
|
|
<script>
|
|
// 插件
|
|
import BScroll from 'better-scroll'
|
|
|
|
export default {
|
|
data () {
|
|
return {
|
|
time: 300,
|
|
BS: null
|
|
}
|
|
},
|
|
mounted () {
|
|
this.scrollInit()
|
|
},
|
|
beforeDestroy () {
|
|
this.scrollDestroy()
|
|
},
|
|
methods: {
|
|
handleScrollTo (y) {
|
|
this.BS.scrollTo(0, -y, this.time)
|
|
},
|
|
handleScrollBy (y) {
|
|
this.BS.scrollBy(0, -y, this.time)
|
|
},
|
|
handleScrollToElement (n) {
|
|
this.BS.scrollToElement(`#demo-bs-item-${n}`, this.time)
|
|
},
|
|
scrollInit () {
|
|
this.BS = new BScroll(this.$refs.wrapper, {
|
|
mouseWheel: true,
|
|
scrollbar: {
|
|
fade: true,
|
|
interactive: false
|
|
}
|
|
})
|
|
},
|
|
scrollDestroy () {
|
|
if (this.BS) {
|
|
this.BS.destroy()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.demo-bs-wrapper {
|
|
height: 400px;
|
|
position: relative;
|
|
overflow: hidden;
|
|
border: 1px solid $color-border-1;
|
|
border-radius: 4px;
|
|
.demo-bs-item {
|
|
line-height: 40px;
|
|
padding-left: 10px;
|
|
border-bottom: 1px solid $color-border-4;
|
|
&:last-child {
|
|
border-bottom: none;
|
|
}
|
|
}
|
|
}
|
|
</style>
|