-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathgetScrollBarSize.tsx
More file actions
87 lines (75 loc) · 2.06 KB
/
getScrollBarSize.tsx
File metadata and controls
87 lines (75 loc) · 2.06 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import getScrollBarSize, {
getTargetScrollBarSize,
} from 'rc-util/es/getScrollBarSize';
import React from 'react';
const cssText = `
#customizeContainer::-webkit-scrollbar {
width: 2em;
height: 23px;
background: blue;
}
#customizeContainer::-webkit-scrollbar-thumb {
background: red;
height: 30px;
}
#scrollContainer {
scrollbar-color: red orange;
scrollbar-width: thin;
}
`;
const Demo = () => {
const defaultRef = React.useRef<HTMLDivElement>(null);
const webkitRef = React.useRef<HTMLDivElement>(null);
const scrollRef = React.useRef<HTMLDivElement>(null);
const [sizeData, setSizeData] = React.useState('');
React.useEffect(() => {
const originSize = getScrollBarSize();
const defaultSize = getTargetScrollBarSize(defaultRef.current);
const webkitSize = getTargetScrollBarSize(webkitRef.current);
const scrollSize = getTargetScrollBarSize(scrollRef.current);
setSizeData(
[
`Origin: ${originSize}`,
`Default: ${defaultSize.width}/${defaultSize.height}`,
`Webkit: ${webkitSize.width}/${webkitSize.height}`,
`Scroll: ${scrollSize.width}/${scrollSize.height}`,
].join(', '),
);
}, []);
return (
<div>
<style dangerouslySetInnerHTML={{ __html: cssText }} />
<div
style={{
width: 300,
height: 100,
overflow: 'scroll',
background: 'yellow',
}}
ref={defaultRef}
>
Origin
</div>
<div
style={{ width: 300, height: 100, overflow: 'auto' }}
id="customizeContainer"
ref={webkitRef}
>
<div style={{ width: '200vw', height: '200vh', background: 'yellow' }}>
Customize `-webkit-scrollbar`
</div>
</div>
<div
style={{ width: 300, height: 100, overflow: 'auto' }}
id="scrollContainer"
ref={scrollRef}
>
<div style={{ width: '200vw', height: '200vh', background: 'yellow' }}>
scrollbar-style
</div>
</div>
<pre>{sizeData}</pre>
</div>
);
};
export default Demo;