MCPcopy Index your code
hub / github.com/electerious/basicScroll / loop

Function loop

src/scripts/main.js:328–358  ·  view source on GitHub ↗
(style, previousScrollTop)

Source from the content-addressed store, hash-verified

326 * @returns {?*}
327 */
328const loop = function(style, previousScrollTop) {
329
330 // Continue loop
331 const repeat = () => {
332
333 // It depends on the browser, but it turns out that closures
334 // are sometimes faster than .bind or .apply.
335 requestAnimationFrame(() => loop(style, previousScrollTop))
336
337 }
338
339 // Get all active instances
340 const activeInstances = getActiveInstances(instances)
341
342 // Only continue when active instances available
343 if (activeInstances.length === 0) return repeat()
344
345 const scrollTop = getScrollTop()
346
347 // Only continue when scrollTop has changed
348 if (previousScrollTop === scrollTop) return repeat()
349 else previousScrollTop = scrollTop
350
351 // Get and set new props of each instance
352 activeInstances
353 .map((instance) => getProps(instance, scrollTop))
354 .forEach(({ elem, props }) => setProps(elem, props))
355
356 repeat()
357
358}
359
360/**
361 * Creates a new instance.

Callers 2

repeatFunction · 0.85
main.jsFile · 0.85

Calls 5

getActiveInstancesFunction · 0.85
repeatFunction · 0.85
getScrollTopFunction · 0.85
getPropsFunction · 0.85
setPropsFunction · 0.85

Tested by

no test coverage detected