MCPcopy Create free account
hub / github.com/caseywebdev/react-list / getScrollPosition

Method getScrollPosition

src/react-list.js:182–204  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

180 }
181
182 getScrollPosition() {
183 // Cache scroll position as this causes a forced synchronous layout.
184 if (typeof this.cachedScrollPosition === 'number') {
185 return this.cachedScrollPosition;
186 }
187 const { scrollParent } = this;
188 const { axis } = this.props;
189 const scrollKey = SCROLL_START_KEYS[axis];
190 const actual =
191 scrollParent === window
192 ? // Firefox always returns document.body[scrollKey] as 0 and Chrome/Safari
193 // always return document.documentElement[scrollKey] as 0, so take
194 // whichever has a value.
195 document.body[scrollKey] || document.documentElement[scrollKey]
196 : scrollParent[scrollKey];
197 const max =
198 this.getScrollSize() - this.props.scrollParentViewportSizeGetter(this);
199 const scroll = Math.max(0, Math.min(actual, max));
200 const el = this.getEl();
201 this.cachedScrollPosition =
202 this.getOffset(scrollParent) + scroll - this.getOffset(el);
203 return this.cachedScrollPosition;
204 }
205
206 setScroll(offset) {
207 const { scrollParent } = this;

Callers 4

getStartAndEndMethod · 0.95
scrollAroundMethod · 0.95
react-list.jsFile · 0.80
index.jsFile · 0.80

Calls 3

getScrollSizeMethod · 0.95
getElMethod · 0.95
getOffsetMethod · 0.95

Tested by

no test coverage detected