Некодим логотипНекодим
МодификацииПубликацииНекодИИмЦены
Некодим логотипНекодим

© 2020-2026 Некодим

Готовые модификации для вашего сайта. Улучшайте функциональность и дизайн без программирования.

Компания

  • Контакты
  • Публичная оферта
  • Политика конфиденциальности
  • Согласие на обработку данных
  • Лицензионное соглашение
  • Реферальная программа

Полезное

  • Модификации
  • Публикации
  • Каталог блоков Tilda
  • MCP для агентов
  • Журнал изменений
  • Доска почёта

Личный кабинет

  • Вход
  • Регистрация
  • Цены
Журнал измененийИстория GitФайлыTilda MCP
Каталог файлов

tilda-animation-ext-1.0.js

Код файла
Версия от 04.12.2026, 04:03:53 МСК
Оригинал на CDNСнимок 56c3b845Полный текст
1101	} else {1102		window.addEventListener(1103			'resize',1104			t_throttle(function () {1105				scrollParallaxOptions = t_animationExt__getParallaxOffests(elements);1106				t_animationExt__animateParallaxByScroll(scrollParallaxOptions);1107			}, 50)1108		);1109	}1110 1111	window.addEventListener('scroll', function () {1112		t_animationExt__animateParallaxByScroll(scrollParallaxOptions);
История файла и сравнение версий
  • 04.12.2026, 04:03:53 · 56c3b845
1113 });
1114}
1115
1116/**
1117 * create object with necessary params to create and animate parallax
1118 *
1119 * @param {HTMLElement[]} elements
1120 * @returns {ObjecForCreatingParallax[]}
1121 */
1122function t_animationExt__getParallaxOffests(elements) {
1123 return elements.map(function (scrollParallaxEl) {
1124 var speedFactor = scrollParallaxEl.getAttribute('data-parallax-speed');
1125 var posY = window.pageYOffset;
1126 var scaledDifference = t_animationExt__calcScaledDiff(scrollParallaxEl);
1127 var blockTopPos = scrollParallaxEl.getBoundingClientRect().top + posY + scaledDifference;
1128 var blockHeight = scrollParallaxEl.clientHeight;
1129 var isAboveParallax = posY > blockTopPos;
1130
1131 // update element top position inside zero-block, that use autoscale
1132 var zoomValue = t_animationExt__getZoom(scrollParallaxEl);
1133 if (window.shouldUseScaleFactor) blockTopPos *= zoomValue;
1134
1135 // apparently parallax equation everyone uses
1136 var percentageY = 0.5;
1137
1138 var speedPoint = 10;
1139 var speed = speedFactor ? t_animationExt__getParallaxSpeed(speedFactor, -speedPoint, speedPoint) : 0;
1140 var positionY = t_animationExt__getParallaxPosition(speed, percentageY);
1141
1142 return {
1143 el: scrollParallaxEl,
1144 elHeight: blockHeight,
1145 elTopPos: blockTopPos,
1146 elBottomPos: blockHeight + blockTopPos,
1147 posY: positionY,
1148 speed: speed,
1149 isAboveParallax: isAboveParallax,
1150 };
1151 });
1152}
1153
1154/**
1155 * create object with necessary params to create and animate parallax
1156 *
1157 * @param {ObjecForCreatingParallax[]} scrollParallaxOptions
1158 */
1159function t_animationExt__animateParallaxByScroll(scrollParallaxOptions) {
1160 var viewportHeight = document.documentElement.clientHeight;
1161 var viewportTopPos = window.pageYOffset;
1162 var viewportBottomPos = viewportTopPos + viewportHeight;
1163 scrollParallaxOptions.forEach(function (opt) {
1164 var isElementInsideViewport =
1165 opt.elTopPos < viewportBottomPos &&
1166 opt.elBottomPos > viewportTopPos &&
1167 opt.elBottomPos <= viewportBottomPos &&
1168 opt.elTopPos >= viewportTopPos;
1169 if (!opt.isAboveParallax && !isElementInsideViewport) return;
1170 var percentageY = (viewportBottomPos - opt.elTopPos) / (opt.elHeight + viewportHeight);
1171 var updatePositionY = t_animationExt__getParallaxPosition(opt.speed, percentageY);
1172 if (!opt.isAboveParallax) {
1173 opt.posY = updatePositionY;
1174 opt.isAboveParallax = true;
1175 }
1176 updatePositionY -= opt.posY;
1177 opt.el.style.transform = 'translateY(' + updatePositionY + 'px)';
1178 });
1179}
1180
1181//============== ending of old fashion way to create parallax animation =============//
1182
1183/**
1184 * get correct trigger offsets in autoscale mode, in case of use Firefox/Opera
1185 *
1186 * @param {HTMLElement} el
1187 * @returns {number} - difference between top position of parent and scaled children
1188 */
1189function t_animationExt__calcScaledDiff(el) {
1190 var scaledWrapper = el.querySelector('.tn-atom__scale-wrapper');
1191 if (window.isOnlyScalable && scaledWrapper && el) {
1192 var elTopPos = el.getBoundingClientRect().top;
1193 var scaleTopPos = scaledWrapper.getBoundingClientRect().top;
1194 var difference = elTopPos - scaleTopPos;
1195 el.setAttribute('data-scaled-diff', difference.toString());
1196 }
1197 var diff = el.getAttribute('data-scaled-diff') || '0';
1198 return parseInt(diff, 10);
1199}
1200
Предыдущие 100 строкСледующие 100 строк