Scrollbar
基础
<template>
<div class="box">
<y-scrollbar ref="scrollbar">
<p
v-for="item in 20"
:key="item"
class="scrollbar-demo-item">
{{ item }}
</p>
</y-scrollbar>
</div>
</template>
<script>
import { defineComponent, ref, onMounted } from 'vue';
export default defineComponent({
name: 'Base',
setup() {
const scrollbar = ref(null);
onMounted(() => {
console.log('scrollbar', scrollbar.value);
if (scrollbar) {
scrollbar.value.scrollTop(100);
}
});
return {
scrollbar,
};
}
});
</script>
<style scoped>
.box {
height: 400px;
width: 400px;
border: 1px solid;
}
.scrollbar-demo-item {
display: flex;
align-items: center;
justify-content: flex-start;
width: 500px;
height: 50px;
padding: 0 16px;
margin: 0;
border-radius: 4px;
border-bottom: 1px dashed #ddd;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
水平滚动
<template>
<y-scrollbar ref="scrollbar">
<div class="scrollbar-flex-content">
<p
v-for="item in 20"
:key="item"
class="scrollbar-demo-item">
{{ item }}
</p>
</div>
</y-scrollbar>
</template>
<script>
import { defineComponent, ref, onMounted } from 'vue';
export default defineComponent({
name: 'Base',
setup() {
const scrollbar = ref(null);
onMounted(() => {
console.log('scrollbar', scrollbar.value);
if (scrollbar) {
scrollbar.value.scrollLeft(100);
}
});
return {
scrollbar,
};
}
});
</script>
<style scoped>
.scrollbar-flex-content {
display: flex;
}
.scrollbar-demo-item {
display: flex;
align-items: center;
justify-content: center;
width: 100px;
height: 50px;
padding: 0 16px;
margin: 0 16px;
border-radius: 4px;
border: 1px dashed #ddd;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
悬停即现
<template>
<div class="box">
<y-scrollbar :hover-visible="true">
<p v-for="item in 20" :key="item" class="scrollbar-demo-item">{{ item }}</p>
</y-scrollbar>
</div>
</template>
<script>
import { defineComponent } from 'vue';
export default defineComponent({
name: 'Base',
});
</script>
<style scoped>
.box {
height: 400px;
width: 400px;
border: 1px solid;
}
.scrollbar-demo-item {
display: flex;
align-items: center;
justify-content: flex-start;
width: 500px;
height: 50px;
padding: 0 16px;
margin: 0;
border-radius: 4px;
border-bottom: 1px dashed #ddd;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
API
Scrollbar props
Property | Description | Type | Accepted Values | Default |
---|---|---|---|---|
hidden | 是否隐藏滚动条 | Boolean | - | false |
layout | 显示水平/垂直方向的滚动条 | String | vertical /horizontal /vertical, horizontal | vertical, horizontal |
hover-visible | 是否鼠标悬停展示滚动条 | Boolean | - | false |
noresize | 是否开启加速模式,该模式下不会监听滚动条 | Boolean | - | false |