MCPcopy
hub / github.com/greensock/GSAP / _scrollCacheFunc

Function _scrollCacheFunc

esm/Observer.js:74–96  ·  view source on GitHub ↗
(f, doNotCache)

Source from the content-addressed store, hash-verified

72 return _normalizer && _normalizer.isPressed || _scrollers.cache++;
73},
74 _scrollCacheFunc = function _scrollCacheFunc(f, doNotCache) {
75 var cachingFunc = function cachingFunc(value) {
76 // since reading the scrollTop/scrollLeft/pageOffsetY/pageOffsetX can trigger a layout, this function allows us to cache the value so it only gets read fresh after a "scroll" event fires (or while we're refreshing because that can lengthen the page and alter the scroll position). when "soft" is true, that means don't actually set the scroll, but cache the new value instead (useful in ScrollSmoother)
77 if (value || value === 0) {
78 _startup && (_win.history.scrollRestoration = "manual"); // otherwise the new position will get overwritten by the browser onload.
79
80 var isNormalizing = _normalizer && _normalizer.isPressed;
81 value = cachingFunc.v = Math.round(value) || (_normalizer && _normalizer.iOS ? 1 : 0); //TODO: iOS Bug: if you allow it to go to 0, Safari can start to report super strange (wildly inaccurate) touch positions!
82
83 f(value);
84 cachingFunc.cacheID = _scrollers.cache;
85 isNormalizing && _bridge("ss", value); // set scroll (notify ScrollTrigger so it can dispatch a "scrollStart" event if necessary
86 } else if (doNotCache || _scrollers.cache !== cachingFunc.cacheID || _bridge("ref")) {
87 cachingFunc.cacheID = _scrollers.cache;
88 cachingFunc.v = f();
89 }
90
91 return cachingFunc.v + cachingFunc.offset;
92 };
93
94 cachingFunc.offset = 0;
95 return f && cachingFunc;
96},
97 _horizontal = {
98 s: _scrollLeft,
99 p: "left",

Callers 2

Observer.jsFile · 0.70
_getScrollFuncFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…