1001if (isAfterStart && isBeforeEnd) {1002step.state = 'started';1003if (animatedHTML.wrapperEl) animatedHTML.wrapperEl.style.willChange = 'transform';1004var progress = trigger - step.start;1005var percentage = step.dist === 0 ? 1 : progress / step.dist;1006elState.prevUnfixedDist = step.prevUnfixedDist;1007t_animationSBS__scrollAnimationCalcStepStyles(elState, step, percentage, i, zoomValue);1008}1009if (isAfterEnd) {1010step.state = 'finished';1011if (animatedHTML.wrapperEl) animatedHTML.wrapperEl.style.willChange = '';
t_animationSBS__scrollAnimationCalcStepStyles(elState, step, 1, i, zoomValue); } if (isBeforeStart && (step.state === 'started' || step.state === 'finished')) { step.state = 'unactive'; if (animatedHTML.wrapperEl) animatedHTML.wrapperEl.style.willChange = ''; t_animationSBS__scrollAnimationCalcStepStyles(elState, step, 0, i, zoomValue); } }); animatedHTML.classList.remove('t396__elem--anim-hidden'); if ( animatedHTML.steps[1] && animatedHTML.steps[1].dist === 0 && animatedHTML.steps[1].styles.opacity === 0 && animatedHTML.steps[1].state === 'unactive' ) { elState.opacity = 0; }}/** * Считает стили элемента для анимации по скроллу: двигает состояние к значениям шага на долю percentage * * @param {scrollElementState} elState - текущее состояние элемента * @param {animatedStepToElement} curStep - текущий шаг * @param {number} percentage - пройденная доля шага от 0 до 1 * @param {number} i - индекс текущего шага * @param {number} zoomValue * @returns {void} */function t_animationSBS__scrollAnimationCalcStepStyles(elState, curStep, percentage, i, zoomValue) { if (curStep.styles.fix === true && curStep.state === 'started') { elState.fix = true; elState.fixedShiftY = 0; } if (curStep.styles.fix === true && curStep.state === 'finished') { elState.fix = false; elState.fixedShiftY += curStep.dist / zoomValue; } if (curStep.styles.fix === true && curStep.state === 'unactive') { if (i > 0 && elState.fix === true) { return; } elState.fix = false; } elState.opacity += percentage * (curStep.styles.opacity - elState.opacity); elState.blur += percentage * (curStep.styles.blur - elState.blur); elState.translateX += percentage * curStep.styles.moveX; elState.translateY += percentage * curStep.styles.moveY; elState.scaleX += percentage * (curStep.styles.scaleX - elState.scaleX); elState.scaleY += percentage * (curStep.styles.scaleY - elState.scaleY); elState.rotate += percentage * curStep.styles.rotate; // цвет смешивается по тому же принципу, что и opacity: от текущего значения к значению шага elState.colors.forEach(colorState => { const target = colorState.target; target.props.forEach(prop => { const stepValue = t_animationSBS__getTargetStepValue(target, curStep.styles, prop); colorState[prop] = t_animationSBS__mixTargetValue(target, prop, colorState[prop], stepValue, percentage); }); });}/** * Применяет посчитанное состояние анимации по скроллу к элементу * * @param {AnimatedHTML} el - текущий элемент * @param {scrollElementState} elState - состояние элемента */function t_animationSBS__scrollAnimationUpdateTransform(el, elState) { if (!el.wrapperEl) return; var zoomValue = t_animationSBS__getZoom(el); var elWillChangeProp = getComputedStyle(el).willChange; var isOnlyScalable = window.isOnlyScalable || t396__isElementUsingCalcZoom(el); if (elState.fix === true && el.wrapperEl.style.position !== 'fixed') { var top = el.triggerOffset - elState.prevUnfixedDist; if (!isOnlyScalable) top /= zoomValue; if (el.scaledDifference) top += el.scaledDifference; el.wrapperEl.style.top = top + 'px'; el.wrapperEl.style.position = 'fixed'; if (elWillChangeProp && elWillChangeProp !== 'auto') el.style.willChange = 'unset'; // фикс для Safari: переносим z-index с элемента на фиксированную tn-atom__sbs-anim-wrapper, // т.к. Safari некорректно рендерит fixed-элемент внутри absolute-родителя с z-index if (el.zIndex) el.wrapperEl.style.zIndex = el.zIndex; } if (elState.fix === false && el.wrapperEl.style.position === 'fixed') {