forked from Saulis/iron-data-table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect-scrollbar-behavior.html
44 lines (39 loc) · 1017 Bytes
/
detect-scrollbar-behavior.html
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
<!-- https://davidwalsh.name/detect-scrollbar-width -->
<style>
:root .scrollbar-measure {
width: 100px;
height: 100px;
overflow: scroll;
position: absolute;
top: -9999px;
}
</style>
<script>
var saulis = window.saulis || {};
/**
* Use `DetectScrollBarBehavior` to detect scrollbar width.
*
* @polymerBehavior
*/
saulis.DetectScrollBarBehavior = {
properties: {
/**
* Automatically detected scroll bar width in px.
*/
scrollBarWidth: {
type: Number,
value: 0
}
},
// registered would be optimal but this doesn't seem to work at that stage.
ready: function() {
var scrollDiv = document.createElement("div");
scrollDiv.className = "scrollbar-measure";
document.body.appendChild(scrollDiv);
// Get the scrollbar width
this.scrollBarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
// Delete the DIV
document.body.removeChild(scrollDiv);
},
};
</script>