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

Function _renderZeroDurationTween

esm/gsap-core.js:470–531  ·  view source on GitHub ↗
(tween, totalTime, suppressEvents, force)

Source from the content-addressed store, hash-verified

468 return data === "isFromStart" || data === "isStart";
469},
470 _renderZeroDurationTween = function _renderZeroDurationTween(tween, totalTime, suppressEvents, force) {
471 var prevRatio = tween.ratio,
472 ratio = totalTime < 0 || !totalTime && (!tween._start && _parentPlayheadIsBeforeStart(tween) && !(!tween._initted && _isFromOrFromStart(tween)) || (tween._ts < 0 || tween._dp._ts < 0) && !_isFromOrFromStart(tween)) ? 0 : 1,
473 // if the tween or its parent is reversed and the totalTime is 0, we should go to a ratio of 0. Edge case: if a from() or fromTo() stagger tween is placed later in a timeline, the "startAt" zero-duration tween could initially render at a time when the parent timeline's playhead is technically BEFORE where this tween is, so make sure that any "from" and "fromTo" startAt tweens are rendered the first time at a ratio of 1.
474 repeatDelay = tween._rDelay,
475 tTime = 0,
476 pt,
477 iteration,
478 prevIteration;
479
480 if (repeatDelay && tween._repeat) {
481 // in case there's a zero-duration tween that has a repeat with a repeatDelay
482 tTime = _clamp(0, tween._tDur, totalTime);
483 iteration = _animationCycle(tTime, repeatDelay);
484 tween._yoyo && iteration & 1 && (ratio = 1 - ratio);
485
486 if (iteration !== _animationCycle(tween._tTime, repeatDelay)) {
487 // if iteration changed
488 prevRatio = 1 - ratio;
489 tween.vars.repeatRefresh && tween._initted && tween.invalidate();
490 }
491 }
492
493 if (ratio !== prevRatio || _reverting || force || tween._zTime === _tinyNum || !totalTime && tween._zTime) {
494 if (!tween._initted && _attemptInitTween(tween, totalTime, force, suppressEvents, tTime)) {
495 // if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately.
496 return;
497 }
498
499 prevIteration = tween._zTime;
500 tween._zTime = totalTime || (suppressEvents ? _tinyNum : 0); // when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect.
501
502 suppressEvents || (suppressEvents = totalTime && !prevIteration); // if it was rendered previously at exactly 0 (_zTime) and now the playhead is moving away, DON'T fire callbacks otherwise they'll seem like duplicates.
503
504 tween.ratio = ratio;
505 tween._from && (ratio = 1 - ratio);
506 tween._time = 0;
507 tween._tTime = tTime;
508 pt = tween._pt;
509
510 while (pt) {
511 pt.r(ratio, pt.d);
512 pt = pt._next;
513 }
514
515 totalTime < 0 && _rewindStartAt(tween, totalTime, suppressEvents, true);
516 tween._onUpdate && !suppressEvents && _callback(tween, "onUpdate");
517 tTime && tween._repeat && !suppressEvents && tween.parent && _callback(tween, "onRepeat");
518
519 if ((totalTime >= tween._tDur || totalTime < 0) && tween.ratio === ratio) {
520 ratio && _removeFromParent(tween, 1);
521
522 if (!suppressEvents && !_reverting) {
523 _callback(tween, ratio ? "onComplete" : "onReverseComplete", true);
524
525 tween._prom && tween._prom();
526 }
527 }

Callers 1

gsap-core.jsFile · 0.70

Calls 9

_isFromOrFromStartFunction · 0.70
_clampFunction · 0.70
_animationCycleFunction · 0.70
_attemptInitTweenFunction · 0.70
_rewindStartAtFunction · 0.70
_callbackFunction · 0.70
_removeFromParentFunction · 0.70
invalidateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…