| 1 |
import getScroll from './getScroll'; |
| 2 |
|
| 3 |
/* |
| 4 |
* Sum or subtract the element scroll values (left and top) from a given rect object |
| 5 |
* @method |
| 6 |
* @memberof Popper.Utils |
| 7 |
* @param {Object} rect - Rect object you want to change |
| 8 |
* @param {HTMLElement} element - The element from the function reads the scroll values |
| 9 |
* @param {Boolean} subtract - set to true if you want to subtract the scroll values |
| 10 |
* @return {Object} rect - The modifier rect object |
| 11 |
*/ |
| 12 |
export default function includeScroll(rect, element, subtract = false) { |
| 13 |
const scrollTop = getScroll(element, 'top'); |
| 14 |
const scrollLeft = getScroll(element, 'left'); |
| 15 |
const modifier = subtract ? -1 : 1; |
| 16 |
rect.top += scrollTop * modifier; |
| 17 |
rect.bottom += scrollTop * modifier; |
| 18 |
rect.left += scrollLeft * modifier; |
| 19 |
rect.right += scrollLeft * modifier; |
| 20 |
return rect; |
| 21 |
} |