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

Function _parsePosition

src/ScrollTrigger.js:454–507  ·  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

452 // 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);
453 // },
454 _parsePosition = (value, trigger, scrollerSize, direction, scroll, marker, markerScroller, self, scrollerBounds, borderWidth, useFixedPosition, scrollerMax, containerAnimation, clampZeroProp) => {
455 _isFunction(value) && (value = value(self));
456 if (_isString(value) && value.substr(0,3) === "max") {
457 value = scrollerMax + (value.charAt(4) === "=" ? _offsetToPx("0" + value.substr(3), scrollerSize) : 0);
458 }
459 let time = containerAnimation ? containerAnimation.time() : 0,
460 p1, p2, element;
461 containerAnimation && containerAnimation.seek(0);
462 isNaN(value) || (value = +value); // convert a string number like "45" to an actual number
463 if (!_isNumber(value)) {
464 _isFunction(trigger) && (trigger = trigger(self));
465 let offsets = (value || "0").split(" "),
466 bounds, localOffset, globalOffset, display;
467 element = _getTarget(trigger, self) || _body;
468 bounds = _getBounds(element) || {};
469 if ((!bounds || (!bounds.left && !bounds.top)) && _getComputedStyle(element).display === "none") { // if display is "none", it won't report getBoundingClientRect() properly
470 display = element.style.display;
471 element.style.display = "block";
472 bounds = _getBounds(element);
473 display ? (element.style.display = display) : element.style.removeProperty("display");
474 }
475 localOffset = _offsetToPx(offsets[0], bounds[direction.d]);
476 globalOffset = _offsetToPx(offsets[1] || "0", scrollerSize);
477 value = bounds[direction.p] - scrollerBounds[direction.p] - borderWidth + localOffset + scroll - globalOffset;
478 markerScroller && _positionMarker(markerScroller, globalOffset, direction, (scrollerSize - globalOffset < 20 || (markerScroller._isStart && globalOffset > 20)));
479 scrollerSize -= scrollerSize - globalOffset; // adjust for the marker
480 } else {
481 containerAnimation && (value = gsap.utils.mapRange(containerAnimation.scrollTrigger.start, containerAnimation.scrollTrigger.end, 0, scrollerMax, value));
482 markerScroller && _positionMarker(markerScroller, scrollerSize, direction, true);
483 }
484 if (clampZeroProp) {
485 self[clampZeroProp] = value || -0.001;
486 value < 0 && (value = 0);
487 }
488 if (marker) {
489 let position = value + scrollerSize,
490 isStart = marker._isStart;
491 p1 = "scroll" + direction.d2;
492 _positionMarker(marker, position, direction, (isStart && position > 20) || (!isStart && (useFixedPosition ? Math.max(_body[p1], _docEl[p1]) : marker.parentNode[p1]) <= position + 1));
493 if (useFixedPosition) {
494 scrollerBounds = _getBounds(markerScroller);
495 useFixedPosition && (marker.style[direction.op.p] = (scrollerBounds[direction.op.p] - direction.op.m - marker._offset) + _px);
496 }
497 }
498 if (containerAnimation && element) {
499 p1 = _getBounds(element);
500 containerAnimation.seek(scrollerMax);
501 p2 = _getBounds(element);
502 containerAnimation._caScrollDist = p1[direction.p] - p2[direction.p];
503 value = value / (containerAnimation._caScrollDist) * scrollerMax;
504 }
505 containerAnimation && containerAnimation.seek(time);
506 return containerAnimation ? value : Math.round(value);
507 },
508 _prefixExp = /(webkit|moz|length|cssText|inset)/i,
509 _reparent = (element, parent, top, left) => {
510 if (element.parentNode !== parent) {

Callers 1

initMethod · 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…