How to use the dom-lib.scrollTop function in dom-lib

To help you get started, we’ve selected a few dom-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rsuite / rsuite / src / Picker / DropdownMenu.tsx View on Github external
updateScrollPoistion() {
    const container = this.menuBodyContainerRef.current;
    let activeItem = container.querySelector(`.${this.addPrefix('item-focus')}`);

    if (!activeItem) {
      activeItem = container.querySelector(`.${this.addPrefix('item-active')}`);
    }

    if (!activeItem) {
      return;
    }
    const position = getPosition(activeItem, container);
    const sTop = scrollTop(container);
    const sHeight = getHeight(container);
    if (sTop > position.top) {
      scrollTop(container, Math.max(0, position.top - 20));
    } else if (position.top > sTop + sHeight) {
      scrollTop(container, Math.max(0, position.top - sHeight + 32));
    }
  }
github rsuite / rsuite / src / Cascader / DropdownMenu.tsx View on Github external
this.menus.forEach(menu => {
      if (!menu) {
        return;
      }

      let activeItem = menu.querySelector(`.${this.addPrefix('item-focus')}`);

      if (!activeItem) {
        activeItem = menu.querySelector(`.${this.addPrefix('item-active')}`);
      }

      if (activeItem) {
        const position = getPosition(activeItem, menu);
        scrollTop(menu, position.top);
      }
    });
  }
github rsuite / rsuite / src / Calendar / TimeDropdown.tsx View on Github external
Object.entries(time).forEach((item: any) => {
      const container: Element = this.container[item[0]];
      const node = container.querySelector(`[data-key="${item[0]}-${item[1]}"]`);
      if (node && container) {
        const { top } = getPosition(node, container);
        scrollTopAnimation(this.container[item[0]], top, scrollTop(this.container[item[0]]) !== 0);
      }
    });
  };
github rsuite / rsuite-table / src / Table.js View on Github external
handleBodyScroll = (event: SyntheticTouchEvent<*>) => {
    if (event.target !== this.tableBody) {
      return;
    }

    let left = scrollLeft(event.target);
    let top = scrollTop(event.target);

    if (top === 0 && left === 0) {
      return;
    }

    this._listenWheel(left, top);

    scrollLeft(event.target, 0);
    scrollTop(event.target, 0);
  };
github rsuite / rsuite / src / utils / scrollTopAnimation.ts View on Github external
export default function scrollTopAnimation(
  target: Element,
  nextTop: number,
  animation = true,
  callback?: (top: number) => void
) {
  let top = scrollTop(target);
  const step = () => {
    scrollTop(target, top > nextTop ? nextTop : top);
    if (top <= nextTop) {
      requestAnimationFramePolyfill(step);
    }
    callback?.(top);
    top += 20;
  };
  if (animation) {
    requestAnimationFramePolyfill(step);
  } else {
    scrollTop(target, nextTop);
  }
}
github rsuite / rsuite / src / utils / scrollTopAnimation.ts View on Github external
animation = true,
  callback?: (top: number) => void
) {
  let top = scrollTop(target);
  const step = () => {
    scrollTop(target, top > nextTop ? nextTop : top);
    if (top <= nextTop) {
      requestAnimationFramePolyfill(step);
    }
    callback?.(top);
    top += 20;
  };
  if (animation) {
    requestAnimationFramePolyfill(step);
  } else {
    scrollTop(target, nextTop);
  }
}
github rsuite / rsuite / docs / fixtures / DocHeader.js View on Github external
handleWindowScroll() {

        if (scrollTop(window) > 30) {
            this.setState({
                overflow: true
            });
            return;
        }

        this.setState({
            overflow: false
        });
    },
    render() {
github rsuite / rsuite / src / utils / overlayPositionUtils.js View on Github external
getContainerDimensions(containerNode) {
        let width, height, scroll;
        if (containerNode.tagName === 'BODY') {
            width = window.innerWidth;
            height = window.innerHeight;
            scroll = scrollTop(ownerDocument(containerNode).documentElement) || scrollTop(containerNode);
        } else {
            ({ width, height } = getOffset(containerNode));
            scroll = scrollTop(containerNode);
        }
        return { width, height, scroll };
    },