MCPcopy
hub / github.com/JedWatson/react-select / animatedScrollTo

Function animatedScrollTo

packages/react-select/src/utils.ts:237–259  ·  view source on GitHub ↗
(
  element: HTMLElement | typeof window,
  to: number,
  duration = 200,
  callback: (element: HTMLElement | typeof window) => void = noop
)

Source from the content-addressed store, hash-verified

235}
236
237export function animatedScrollTo(
238 element: HTMLElement | typeof window,
239 to: number,
240 duration = 200,
241 callback: (element: HTMLElement | typeof window) => void = noop
242) {
243 const start = getScrollTop(element);
244 const change = to - start;
245 const increment = 10;
246 let currentTime = 0;
247
248 function animateScroll() {
249 currentTime += increment;
250 const val = easeOutCubic(currentTime, start, change, duration);
251 scrollTo(element, val);
252 if (currentTime < duration) {
253 window.requestAnimationFrame(animateScroll);
254 } else {
255 callback(element);
256 }
257 }
258 animateScroll();
259}
260
261// Scroll Into View
262// ------------------------------

Callers 2

getMenuPlacementFunction · 0.90
PageNavClass · 0.90

Calls 2

getScrollTopFunction · 0.85
animateScrollFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…