MCPcopy Create free account
hub / github.com/bvaughn/react-virtualized / scrollTo

Function scrollTo

lib/utils/scrollElement/useScrollElementLink.ts:71–96  ·  view source on GitHub ↗
(scrollTop)

Source from the content-addressed store, hash-verified

69
70 source: {
71 scrollTo(scrollTop) {
72 const { element } = instance;
73 if (element === null) {
74 return false;
75 }
76
77 // Measure the position again, in case content above the component has changed size since it was last measured
78 const targetElement = instance.target.getElement();
79 const positionFromTop = targetElement
80 ? getPositionOffset(targetElement, element).top
81 : 0;
82
83 const scrollOffset = getScrollOffset(element);
84 const top = scrollTop + positionFromTop;
85 if (Math.abs(scrollOffset.top - top) < 1) {
86 return false;
87 }
88
89 if (typeof element.scrollTo === "function") {
90 // Preserve the current horizontal scroll position
91 element.scrollTo(scrollOffset.left, top);
92 } else {
93 (element as Element).scrollTop = top;
94 }
95 return true;
96 }
97 },
98
99 update(isScrolling) {

Callers

nothing calls this directly

Calls 2

getPositionOffsetFunction · 0.90
getScrollOffsetFunction · 0.90

Tested by

no test coverage detected