/**
 * 找到最近的触发滚动事件的元素
 * @param {Element} element
 * @param {Element} rootParent
 * @returns {Element | window}
 */
export function getScrollEventTarget(element) {
  var rootParent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
  var node = element;

  while (node && node.tagName !== 'HTML' && node.tagName !== 'BODY' && node.nodeType === 1 && node !== rootParent) {
    var _window$getComputedSt = window.getComputedStyle(node),
        overflowY = _window$getComputedSt.overflowY;

    if (overflowY === 'scroll' || overflowY === 'auto') {
      return node;
    }

    node = node.parentNode;
  }

  return rootParent;
} // 获取滚动高度

export function getScrollTop(element) {
  return 'scrollTop' in element ? element.scrollTop : element.pageYOffset;
} // 设置滚动高度

export function setScrollTop(element, value) {
  'scrollTop' in element ? element.scrollTop = value : element.scrollTo(element.scrollX, value);
} // 获取元素距离顶部高度

export function getElementTop(element) {
  return (element === window ? 0 : element.getBoundingClientRect().top) + getScrollTop(window);
}
export function getVisibleHeight(element) {
  return element === window ? element.innerHeight : element.getBoundingClientRect().height;
}
//# sourceMappingURL=scroll.js.map