Former-commit-id: 1eedb50a5b7de4f3d73ea7b0605eb53b7d90b103 [formerly 1eedb50a5b7de4f3d73ea7b0605eb53b7d90b103 [formerly 1eedb50a5b7de4f3d73ea7b0605eb53b7d90b103 [formerly 1eedb50a5b7de4f3d73ea7b0605eb53b7d90b103 [formerly ebdf53468c985fef5fa9a4a5ab85e2ca959b400e [formerly 6c5fd403f0d2cc243f4c81c41dabe8b3b0ce09b5]]]]] Former-commit-id: 43b72493fb125d14ad23ee6076e617482aa3359f Former-commit-id: 3f6398f32d221d809f02c493bd90e61cc7c2187c Former-commit-id: 5e13356ca801d9c4dbb58b2ba0388cc3e78bfe58 [formerly a3f51e47179a560bbc63f42d1e72fbdf9c11f74e] Former-commit-id: 60fd5e1717d51ced424b18afd5accb17183bb4a0 Former-commit-id: 61a45cb809874299bc25756d13abc98a7c46636d Former-commit-id: f157695943693adfa02fd6b0c19add2a435757d5 Former-commit-id: 079fc63f3d96b319348a49ee1b7e0025d7705ed2 Former-commit-id: 8f8794c7db29f086e862c073678c163f21e5a519
91 lines
2.4 KiB
Vue
91 lines
2.4 KiB
Vue
<template>
|
|
<d2-container>
|
|
<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>
|
|
</d2-container>
|
|
</template>
|
|
|
|
<script>
|
|
import BScroll from 'better-scroll'
|
|
export default {
|
|
data () {
|
|
return {
|
|
time: 300,
|
|
BS: null
|
|
}
|
|
},
|
|
mounted () {
|
|
this.BS = new BScroll(this.$refs.wrapper, {
|
|
mouseWheel: true,
|
|
scrollbar: {
|
|
fade: true
|
|
}
|
|
})
|
|
},
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
@import '~@/assets/style/public.scss';
|
|
.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>
|
|
|