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

Class ScrollTrigger

src/ScrollTrigger.js:597–1484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595
596
597export class ScrollTrigger {
598
599 constructor(vars, animation) {
600 _coreInitted || ScrollTrigger.register(gsap) || console.warn("Please gsap.registerPlugin(ScrollTrigger)");
601 _context(this);
602 this.init(vars, animation);
603 }
604
605 init(vars, animation) {
606 this.progress = this.start = 0;
607 this.vars && this.kill(true, true); // in case it's being initted again
608 if (!_enabled) {
609 this.update = this.refresh = this.kill = _passThrough;
610 return;
611 }
612 vars = _setDefaults((_isString(vars) || _isNumber(vars) || vars.nodeType) ? {trigger: vars} : vars, _defaults);
613 let {onUpdate, toggleClass, id, onToggle, onRefresh, scrub, trigger, pin, pinSpacing, invalidateOnRefresh, anticipatePin, onScrubComplete, onSnapComplete, once, snap, pinReparent, pinSpacer, containerAnimation, fastScrollEnd, preventOverlaps} = vars,
614 direction = vars.horizontal || (vars.containerAnimation && vars.horizontal !== false) ? _horizontal : _vertical,
615 isToggle = !scrub && scrub !== 0,
616 scroller = _getTarget(vars.scroller || _win),
617 scrollerCache = gsap.core.getCache(scroller),
618 isViewport = _isViewport(scroller),
619 useFixedPosition = ("pinType" in vars ? vars.pinType : _getProxyProp(scroller, "pinType") || (isViewport && "fixed")) === "fixed",
620 callbacks = [vars.onEnter, vars.onLeave, vars.onEnterBack, vars.onLeaveBack],
621 toggleActions = isToggle && vars.toggleActions.split(" "),
622 markers = "markers" in vars ? vars.markers : _defaults.markers,
623 borderWidth = isViewport ? 0 : parseFloat(_getComputedStyle(scroller)["border" + direction.p2 + _Width]) || 0,
624 self = this,
625 onRefreshInit = vars.onRefreshInit && (() => vars.onRefreshInit(self)),
626 getScrollerSize = _getSizeFunc(scroller, isViewport, direction),
627 getScrollerOffsets = _getOffsetsFunc(scroller, isViewport),
628 lastSnap = 0,
629 lastRefresh = 0,
630 prevProgress = 0,
631 scrollFunc = _getScrollFunc(scroller, direction),
632 tweenTo, pinCache, snapFunc, scroll1, scroll2, start, end, markerStart, markerEnd, markerStartTrigger, markerEndTrigger, markerVars, executingOnRefresh,
633 change, pinOriginalState, pinActiveState, pinState, spacer, offset, pinGetter, pinSetter, pinStart, pinChange, spacingStart, spacerState, markerStartSetter, pinMoves,
634 markerEndSetter, cs, snap1, snap2, scrubTween, scrubSmooth, snapDurClamp, snapDelayedCall, prevScroll, prevAnimProgress, caMarkerSetter, customRevertReturn;
635
636 // for the sake of efficiency, _startClamp/_endClamp serve like a truthy value indicating that clamping was enabled on the start/end, and ALSO store the actual pre-clamped numeric value. We tap into that in ScrollSmoother for speed effects. So for example, if start="clamp(top bottom)" results in a start of -100 naturally, it would get clamped to 0 but -100 would be stored in _startClamp.
637 self._startClamp = self._endClamp = false;
638 self._dir = direction;
639 anticipatePin *= 45;
640 self.scroller = scroller;
641 self.scroll = containerAnimation ? containerAnimation.time.bind(containerAnimation) : scrollFunc;
642 scroll1 = scrollFunc();
643 self.vars = vars;
644 animation = animation || vars.animation;
645 if ("refreshPriority" in vars) {
646 _sort = 1;
647 vars.refreshPriority === -9999 && (_primary = self); // used by ScrollSmoother
648 }
649 scrollerCache.tweenScroll = scrollerCache.tweenScroll || {
650 top: _getTweenCreator(scroller, _vertical),
651 left: _getTweenCreator(scroller, _horizontal)
652 };
653 self.tweenTo = tweenTo = scrollerCache.tweenScroll[direction.p];
654 self.scrubDuration = value => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…