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

Function _parsePosition

esm/ScrollTrigger.js:738–808  ·  view source on GitHub ↗
(value, trigger, scrollerSize, direction, scroll, marker, markerScroller, self, scrollerBounds, borderWidth, useFixedPosition, scrollerMax, containerAnimation, clampZeroProp)

Source from the content-addressed store, hash-verified

736// return _parsePosition(position, _getTarget(trigger), _getSizeFunc(scroller, isViewport, direction)(), direction, _getScrollFunc(scroller, direction)(), 0, 0, 0, _getOffsetsFunc(scroller, isViewport)(), isViewport ? 0 : parseFloat(_getComputedStyle(scroller)["border" + direction.p2 + _Width]) || 0, 0, containerAnimation ? containerAnimation.duration() : _maxScroll(scroller), containerAnimation);
737// },
738_parsePosition = function _parsePosition(value, trigger, scrollerSize, direction, scroll, marker, markerScroller, self, scrollerBounds, borderWidth, useFixedPosition, scrollerMax, containerAnimation, clampZeroProp) {
739 _isFunction(value) && (value = value(self));
740
741 if (_isString(value) && value.substr(0, 3) === "max") {
742 value = scrollerMax + (value.charAt(4) === "=" ? _offsetToPx("0" + value.substr(3), scrollerSize) : 0);
743 }
744
745 var time = containerAnimation ? containerAnimation.time() : 0,
746 p1,
747 p2,
748 element;
749 containerAnimation && containerAnimation.seek(0);
750 isNaN(value) || (value = +value); // convert a string number like "45" to an actual number
751
752 if (!_isNumber(value)) {
753 _isFunction(trigger) && (trigger = trigger(self));
754 var offsets = (value || "0").split(" "),
755 bounds,
756 localOffset,
757 globalOffset,
758 display;
759 element = _getTarget(trigger, self) || _body;
760 bounds = _getBounds(element) || {};
761
762 if ((!bounds || !bounds.left && !bounds.top) && _getComputedStyle(element).display === "none") {
763 // if display is "none", it won't report getBoundingClientRect() properly
764 display = element.style.display;
765 element.style.display = "block";
766 bounds = _getBounds(element);
767 display ? element.style.display = display : element.style.removeProperty("display");
768 }
769
770 localOffset = _offsetToPx(offsets[0], bounds[direction.d]);
771 globalOffset = _offsetToPx(offsets[1] || "0", scrollerSize);
772 value = bounds[direction.p] - scrollerBounds[direction.p] - borderWidth + localOffset + scroll - globalOffset;
773 markerScroller && _positionMarker(markerScroller, globalOffset, direction, scrollerSize - globalOffset < 20 || markerScroller._isStart && globalOffset > 20);
774 scrollerSize -= scrollerSize - globalOffset; // adjust for the marker
775 } else {
776 containerAnimation && (value = gsap.utils.mapRange(containerAnimation.scrollTrigger.start, containerAnimation.scrollTrigger.end, 0, scrollerMax, value));
777 markerScroller && _positionMarker(markerScroller, scrollerSize, direction, true);
778 }
779
780 if (clampZeroProp) {
781 self[clampZeroProp] = value || -0.001;
782 value < 0 && (value = 0);
783 }
784
785 if (marker) {
786 var position = value + scrollerSize,
787 isStart = marker._isStart;
788 p1 = "scroll" + direction.d2;
789
790 _positionMarker(marker, position, direction, isStart && position > 20 || !isStart && (useFixedPosition ? Math.max(_body[p1], _docEl[p1]) : marker.parentNode[p1]) <= position + 1);
791
792 if (useFixedPosition) {
793 scrollerBounds = _getBounds(markerScroller);
794 useFixedPosition && (marker.style[direction.op.p] = scrollerBounds[direction.op.p] - direction.op.m - marker._offset + _px);
795 }

Callers 1

ScrollTrigger.jsFile · 0.70

Calls 11

_getTargetFunction · 0.90
timeMethod · 0.80
seekMethod · 0.80
_isFunctionFunction · 0.70
_isStringFunction · 0.70
_offsetToPxFunction · 0.70
_isNumberFunction · 0.70
_getBoundsFunction · 0.70
_getComputedStyleFunction · 0.70
_positionMarkerFunction · 0.70
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…