expand-element / getIsScrollX
Function: getIsScrollX()
ts
function getIsScrollX(el: HTMLElement): boolean1
**单独获取元素的 横向 内容是否超出,应该有滚动条 **
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;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 { getIsScrollX } from 'expand-element'
import { getIsScrollX } 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 = getIsScrollX(noScroll.value)
noScrollCode.value = JSON.stringify(res, null, 2)
}
}
const scrollFn = () => {
if (scroll.value) {
const res = getIsScrollX(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
boolean
元素内容 横向 是否超出,值为布尔值,非浏览器环境时,返回 false。