-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.scrollParams.js
72 lines (58 loc) · 2.37 KB
/
jquery.scrollParams.js
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
(function ($) {
$.fn.scrollParams = function () {
var test = {
window: $(window),
document: $(document),
docEl: $(document.documentElement),
html: $("html"),
body: $(document.body)
};
return function () {
var scrollbars = {
vertical: {
width: 0,
visible: false,
_test: Number.MAX_VALUE
},
horizontal: {
width: 0,
visible: false,
_test: Number.MAX_VALUE
}
};
for (var prop in test) {
scrollbars.horizontal.visible |= test[prop].width() > scrollbars.horizontal._test;
scrollbars.horizontal._test = test[prop].width();
}
for (var prop in test) {
scrollbars.vertical.visible |= test[prop].height() > scrollbars.vertical._test;
scrollbars.vertical._test = test[prop].height();
}
var docStyle = document.documentElement.style;
var oldStyle = function () {
cStyle = window.getComputedStyle(document.documentElement);
return {
overflow: cStyle["overflow"],
overflowX: cStyle["overflow-x"],
overflowY: cStyle["overflow-y"]
}
} ();
docStyle.overflowY = "hidden";
scrollbars.horizontal.width = document.documentElement.clientWidth;
docStyle.overflowY = "scroll";
scrollbars.horizontal.width -= document.documentElement.clientWidth;
docStyle.overflow = oldStyle.overflow;
docStyle.overflowY = oldStyle.overflowY;
docStyle.overflowX = oldStyle.overflowX;
docStyle.overflowX = "hidden";
scrollbars.vertical.width = document.documentElement.clientHeight;
docStyle.overflowX = "scroll";
scrollbars.vertical.width -= document.documentElement.clientHeight;
docStyle.overflow = oldStyle.overflow;
docStyle.overflowY = oldStyle.overflowY;
docStyle.overflowX = oldStyle.overflowX;
return scrollbars;
} ();
};
$.scrollParams = function () { return $("<div>").scrollParams(); };
})(jQuery)