expand-element / getIsScroll
Function: getIsScroll()
ts
function getIsScroll(el: HTMLElement): {
x: boolean;
y: boolean;
}1
2
3
4
2
3
4
**获取元素的 横纵向 内容是否超出,应该有滚动条 **
version: v0.0.4+example
noScroll
Scroll
Details
vue
<template>
<div class="scroll-box" ref="noScroll">
<div style="width: 100px;background-color: aqua;">noScroll</div>
</div>
<div>
<button class="btn" @click="noScrollFn">获取noScroll</button>
<pre class="pre">{{ noScrollCode }}</pre>
</div>
<div class="scroll-box" ref="scroll">
<div style="width: 1000px;height: 100px;background-color: aqua;">Scroll</div>
</div>
<div>
<button class="btn" @click="scrollFn">获取Scroll</button>
<pre class="pre">{{ scrollCode }}</pre>
</div>
</template>
<script lang="ts" setup>
import { ref } from 'vue'
// import { getIsScroll } from 'expand-element'
import { getIsScroll } from './../../../../lib/main'
const noScroll = ref<HTMLElement | null>(null)
const scroll = ref<HTMLElement | null>(null)
const noScrollCode = ref('')
const scrollCode = ref('')
const noScrollFn = () => {
if (noScroll.value) {
const res = getIsScroll(noScroll.value)
noScrollCode.value = JSON.stringify(res, null, 2)
}
}
const scrollFn = () => {
if (scroll.value) {
const res = getIsScroll(scroll.value)
scrollCode.value = JSON.stringify(res, null, 2)
}
}
</script>
<style scoped>
.scroll-box {
height: 88px;
overflow: auto;
background-color: #ccc;
margin-bottom: 15px;
}
</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
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
Parameters
el
HTMLElement
要获取的元素。
Returns
ts
{
x: boolean;
y: boolean;
}1
2
3
4
2
3
4
包含元素是否超出的对象,包含 x 和 y 属性,值为布尔值,非浏览器环境时,返回 { x: false, y: false }。
x
ts
x: boolean = false;1
y
ts
y: boolean = false;1