MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / updateScrollResize

Method updateScrollResize

src/utils.ts:590–609  ·  view source on GitHub ↗

* @internal Function used to scroll the page. * * @param event `MouseEvent` that triggers the resize * @param el `HTMLElement` that's being resized * @param distance Distance from the V edges to start scrolling

(event: MouseEvent, el: HTMLElement, distance: number)

Source from the content-addressed store, hash-verified

588 * @param distance Distance from the V edges to start scrolling
589 */
590 static updateScrollResize(event: MouseEvent, el: HTMLElement, distance: number): void {
591 const scrollEl = Utils.getScrollElement(el);
592 const height = scrollEl.clientHeight;
593 // #1727 event.clientY is relative to viewport, so must compare this against position of scrollEl getBoundingClientRect().top
594 // #1745 Special situation if scrollEl is document 'html': here browser spec states that
595 // clientHeight is height of viewport, but getBoundingClientRect() is rectangle of html element;
596 // this discrepancy arises because in reality scrollbar is attached to viewport, not html element itself.
597 const offsetTop = (scrollEl === Utils.getScrollElement()) ? 0 : scrollEl.getBoundingClientRect().top;
598 const pointerPosY = event.clientY - offsetTop;
599 const top = pointerPosY < distance;
600 const bottom = pointerPosY > height - distance;
601
602 if (top) {
603 // This also can be done with a timeout to keep scrolling while the mouse is
604 // in the scrolling zone. (will have smoother behavior)
605 scrollEl.scrollBy({ behavior: 'smooth', top: pointerPosY - distance});
606 } else if (bottom) {
607 scrollEl.scrollBy({ behavior: 'smooth', top: distance - (height - pointerPosY)});
608 }
609 }
610
611 /** single level clone, returning a new object with same top fields. This will share sub objects and arrays */
612 static clone<T>(obj: T): T {

Callers 2

_dragOrResizeMethod · 0.80
utils-spec.tsFile · 0.80

Calls 1

getScrollElementMethod · 0.80

Tested by

no test coverage detected