OLD | NEW |
(Empty) | |
| 1 function getViewportRect(target) { |
| 2 // Q: What's the correct way to get the scroller bounds (if the scroller is th
e document)? |
| 3 if (target == document.scrollingElement) { |
| 4 return { |
| 5 left: 0, |
| 6 top: 0, |
| 7 width: window.innerWidth, |
| 8 height: window.innerHeight, |
| 9 right: window.innerWidth, |
| 10 bottom: window.innerHeight |
| 11 }; |
| 12 } |
| 13 return target.getBoundingClientRect(); |
| 14 } |
| 15 |
| 16 function getContainingBlockElement(node) { |
| 17 if (node.style.position == 'absolute') { |
| 18 do { |
| 19 node = node.parentNode; |
| 20 } while (['absolute', 'fixed', 'relative', 'sticky'].indexOf(getComputedStyl
e(node).position) == -1); |
| 21 return node || document; |
| 22 } |
| 23 do { |
| 24 node = node.parentNode; |
| 25 } while (['block', 'inline-block', 'list-item', 'run-in', 'table', 'table-ce
ll'].indexOf(getComputedStyle(node).display) == -1); |
| 26 return node || document; |
| 27 } |
| 28 |
| 29 function isScrollable(element) { |
| 30 // Q: Why is scrollHeight > clientHeight on body when document is scrollable n
ode? |
| 31 return element.scrollHeight > element.clientHeight || element == document.scro
llingElement; |
| 32 } |
| 33 |
| 34 function getContainingScrollingElement(element) { |
| 35 do { |
| 36 element = getContainingBlockElement(element); |
| 37 } while (element && !isScrollable(element)); |
| 38 return element; |
| 39 } |
OLD | NEW |