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

Method render

src/gsap-core.js:2420–2538  ·  view source on GitHub ↗
(totalTime, suppressEvents, force)

Source from the content-addressed store, hash-verified

2418 }
2419
2420 render(totalTime, suppressEvents, force) {
2421 let prevTime = this._time,
2422 tDur = this._tDur,
2423 dur = this._dur,
2424 isNegative = totalTime < 0,
2425 tTime = (totalTime > tDur - _tinyNum && !isNegative) ? tDur : (totalTime < _tinyNum) ? 0 : totalTime,
2426 time, pt, iteration, cycleDuration, prevIteration, isYoyo, ratio, timeline;
2427 if (!dur) {
2428 _renderZeroDurationTween(this, totalTime, suppressEvents, force);
2429 } else if (tTime !== this._tTime || !totalTime || force || (!this._initted && this._tTime) || (this._startAt && (this._zTime < 0) !== isNegative) || this._lazy) { // this senses if we're crossing over the start time, in which case we must record _zTime and force the render, but we do it in this lengthy conditional way for performance reasons (usually we can skip the calculations): this._initted && (this._zTime < 0) !== (totalTime < 0)
2430 time = tTime;
2431 timeline = this.timeline;
2432 if (this._repeat) { //adjust the time for repeats and yoyos
2433 cycleDuration = dur + this._rDelay;
2434 if (this._repeat < -1 && isNegative) {
2435 return this.totalTime(cycleDuration * 100 + totalTime, suppressEvents, force);
2436 }
2437 time = _roundPrecise(tTime % cycleDuration); //round to avoid floating point errors. (4 % 0.8 should be 0 but some browsers report it as 0.79999999!)
2438 if (tTime === tDur) { // the tDur === tTime is for edge cases where there's a lengthy decimal on the duration and it may reach the very end but the time is rendered as not-quite-there (remember, tDur is rounded to 4 decimals whereas dur isn't)
2439 iteration = this._repeat;
2440 time = dur;
2441 } else {
2442 prevIteration = _roundPrecise(tTime / cycleDuration); // full decimal version of iterations, not the previous iteration (we're reusing prevIteration variable for efficiency)
2443 iteration = ~~prevIteration;
2444 if (iteration && iteration === prevIteration) {
2445 time = dur;
2446 iteration--;
2447 } else if (time > dur) {
2448 time = dur;
2449 }
2450 }
2451 isYoyo = this._yoyo && (iteration & 1);
2452 if (isYoyo) time = dur - time;
2453 prevIteration = _animationCycle(this._tTime, cycleDuration);
2454 if (time === prevTime && !force && this._initted && iteration === prevIteration) {
2455 //could be during the repeatDelay part. No need to render and fire callbacks.
2456 this._tTime = tTime;
2457 return this;
2458 }
2459 if (iteration !== prevIteration) {
2460 //repeatRefresh functionality
2461 if (this.vars.repeatRefresh && !isYoyo && !this._lock && time !== cycleDuration && this._initted) { // this._time will === cycleDuration when we render at EXACTLY the end of an iteration. Without this condition, it'd often do the repeatRefresh render TWICE (again on the very next tick).
2462 this._lock = force = 1; //force, otherwise if lazy is true, the _attemptInitTween() will return and we'll jump out and get caught bouncing on each tick.
2463 this.render(_roundPrecise(cycleDuration * iteration), true).invalidate()._lock = 0;
2464 }
2465 }
2466 }
2467
2468 if (!this._initted) {
2469 if (_attemptInitTween(this, isNegative ? totalTime : time, force, suppressEvents, tTime)) {
2470 this._tTime = 0; // in constructor if immediateRender is true, we set _tTime to -_tinyNum to have the playhead cross the starting point but we can't leave _tTime as a negative number.
2471 return this;
2472 }
2473 if (prevTime !== this._time && !(force && this.vars.repeatRefresh && iteration !== prevIteration)) { // rare edge case - during initialization, an onUpdate in the _startAt (.fromTo()) might force this tween to render at a different spot in which case we should ditch this render() call so that it doesn't revert the values. But we also don't want to dump if we're doing a repeatRefresh render!
2474 return this;
2475 }
2476 if (dur !== this._dur) { // while initting, a plugin like InertiaPlugin might alter the duration, so rerun from the start to ensure everything renders as it should.
2477 return this.render(totalTime, suppressEvents, force);

Callers 15

constructorMethod · 0.95
resetToMethod · 0.95
_refreshAllFunction · 0.45
ScrollTrigger.jsFile · 0.45
_lazyRenderFunction · 0.45
_lazySafeRenderFunction · 0.45
_rewindStartAtFunction · 0.45
_postAddChecksFunction · 0.45
gsap-core.jsFile · 0.45
_initTweenFunction · 0.45
TweenFunction · 0.45

Calls 10

timeScaleMethod · 0.80
_renderZeroDurationTweenFunction · 0.70
_roundPreciseFunction · 0.70
_animationCycleFunction · 0.70
_attemptInitTweenFunction · 0.70
_callbackFunction · 0.70
_rewindStartAtFunction · 0.70
_removeFromParentFunction · 0.70
totalTimeMethod · 0.45
invalidateMethod · 0.45

Tested by

no test coverage detected