MCPcopy Index your code
hub / github.com/shipshapecode/tether / getScrollHandleBounds

Function getScrollHandleBounds

src/js/utils/bounds.js:46–104  ·  view source on GitHub ↗
(body, target)

Source from the content-addressed store, hash-verified

44 * @return {{left: number, width: number, height: number}}
45 */
46export function getScrollHandleBounds(body, target) {
47 let bounds;
48 // We have to do the check for the scrollTop and if target === document.body here and set to variables
49 // because we may reset target below.
50 const targetScrollTop = target.scrollTop;
51 const targetIsBody = target === document.body;
52
53 if (targetIsBody) {
54 target = document.documentElement;
55
56 bounds = {
57 left: pageXOffset,
58 top: pageYOffset,
59 height: innerHeight,
60 width: innerWidth
61 };
62 } else {
63 bounds = getBounds(body, target);
64 }
65
66 const style = getComputedStyle(target);
67
68 const hasBottomScroll = (
69 target.scrollWidth > target.clientWidth ||
70 [style.overflow, style.overflowX].indexOf('scroll') >= 0 ||
71 !targetIsBody
72 );
73
74 let scrollBottom = 0;
75 if (hasBottomScroll) {
76 scrollBottom = 15;
77 }
78
79 const height = bounds.height - parseFloat(style.borderTopWidth) - parseFloat(style.borderBottomWidth) - scrollBottom;
80
81 const out = {
82 width: 15,
83 height: height * 0.975 * (height / target.scrollHeight),
84 left: bounds.left + bounds.width - parseFloat(style.borderLeftWidth) - 15
85 };
86
87 let fitAdj = 0;
88 if (height < 408 && targetIsBody) {
89 fitAdj = -0.00011 * Math.pow(height, 2) - 0.00727 * height + 22.58;
90 }
91
92 if (!targetIsBody) {
93 out.height = Math.max(out.height, 24);
94 }
95
96 const scrollPercentage = targetScrollTop / (target.scrollHeight - height);
97 out.top = scrollPercentage * (height - out.height - fitAdj) + bounds.top + parseFloat(style.borderTopWidth);
98
99 if (targetIsBody) {
100 out.height = Math.max(out.height, 24);
101 }
102
103 return out;

Callers 2

bounds.spec.jsFile · 0.90
getTargetBoundsMethod · 0.90

Calls 1

getBoundsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…