| 1 |
/** |
| 2 |
* Gets the scroll value of the given element in the given side (top and left) |
| 3 |
* @method |
| 4 |
* @memberof Popper.Utils |
| 5 |
* @argument {Element} element |
| 6 |
* @argument {String} side `top` or `left` |
| 7 |
* @returns {number} amount of scrolled pixels |
| 8 |
*/ |
| 9 |
export default function getScroll(element, side = 'top') { |
| 10 |
const upperSide = side === 'top' ? 'scrollTop' : 'scrollLeft'; |
| 11 |
const nodeName = element.nodeName; |
| 12 |
|
| 13 |
if (nodeName === 'BODY' || nodeName === 'HTML') { |
| 14 |
const html = element.ownerDocument.documentElement; |
| 15 |
const scrollingElement = element.ownerDocument.scrollingElement || html; |
| 16 |
return scrollingElement[upperSide]; |
| 17 |
} |
| 18 |
|
| 19 |
return element[upperSide]; |
| 20 |
} |