Каталог файловtilda-animation-ext-1.0.js
1001 1002 var event = document.createEvent('Event');1003 event.initEvent('parallaxReady', true, true);1004 1005 scrollParallaxEl.isAboveParallax = isAboveParallax;1006 scrollParallaxEl.speed = speed;1007 scrollParallaxEl.topPos = blockTopPos;1008 scrollParallaxEl.bottomPos = blockTopPos + blockHeight;1009 scrollParallaxEl.isStarted = false;1010 scrollParallaxEl.style.transform = '';1011 var scrollParallaxImgEl = scrollParallaxEl.querySelector('.t-img');1012
История файла и сравнение версий
if (scrollParallaxImgEl) {
1014 scrollParallaxImgEl.complete && 1015 scrollParallaxImgEl.clientHeight !== 0 && 1016 scrollParallaxImgEl.src && 1017 scrollParallaxImgEl.clientWidth 1019 t_animationExt__triggerParallaxInit(scrollParallaxEl, event); 1021 scrollParallaxImgEl.addEventListener('load', function () { 1022 t_animationExt__triggerParallaxInit(scrollParallaxEl, event); 1026 t_animationExt__triggerParallaxInit(scrollParallaxEl, event); 1031function t_animationExt__triggerParallaxInit(scrollParallaxEl, event) { 1032 scrollParallaxEl.isReady = true; 1033 scrollParallaxEl.dispatchEvent(event); 1038 * @param {ScrollParallaxElement} scrollParallaxEl 1039 * @param {'start' | 'animate'} status - start status selected, when element placed inside viewport position, 1040 * animated - when user scrolled and for element set necessary transform by axisY 1042function t_animationExt__animateParallaxOnScroll(scrollParallaxEl, status) { 1043 if (status === 'animate' && !scrollParallaxEl.isStarted) return; 1044 requestAnimationFrame(function () { 1045 t_animationExt__animateParallaxOnScroll(scrollParallaxEl, 'animate'); 1047 var viewportHeight = document.documentElement.clientHeight; 1048 var viewportTopPos = window.pageYOffset; 1049 var viewportBottomPos = viewportTopPos + viewportHeight; 1050 var percentageY = (viewportBottomPos - scrollParallaxEl.topPos) / (scrollParallaxEl.clientHeight + viewportHeight); 1051 var updatePositionY = t_animationExt__getParallaxPosition(scrollParallaxEl.speed, percentageY); 1052 if (status === 'start') { 1053 scrollParallaxEl.posY = updatePositionY; 1054 scrollParallaxEl.isStarted = true; 1056 updatePositionY -= scrollParallaxEl.posY; 1057 scrollParallaxEl.style.transform = 'translateY(' + updatePositionY + 'px)'; 1062 * get parents of parallax element 1064 * @param {HTMLElement[]} elements 1065 * @returns {HTMLElement[]} 1067function t_animationExt__findParallaxParents(elements) { 1070 elements.forEach(function (el) { 1071 var parent = el.closest('.r'); 1072 if (!parent) return; 1073 var isUniqueID = IDs.indexOf(parent.id) === -1; 1074 if (!isUniqueID) return; 1075 IDs.push(parent.id); 1076 parents.push(parent); 1081//============== old fashion way to create parallax animation =============// 1084 * find element by selector, get it offsets and create parallax. Update values by resize/orientation change 1086 * @param {string} selector 1088function t_animationExt__createParallaxByScroll(selector) { 1089 var elements = Array.prototype.slice.call(document.querySelectorAll(selector)); 1090 var scrollParallaxOptions = t_animationExt__getParallaxOffests(elements); 1092 // update offsets in resize 1093 if (window.t_animationExt__isMobile) { 1094 window.addEventListener('orientationchange', function () { 1095 // wait to get correct viewport height 1096 setTimeout(function () { 1097 scrollParallaxOptions = t_animationExt__getParallaxOffests(elements); 1098 t_animationExt__animateParallaxByScroll(scrollParallaxOptions);