(function(){ function initScroller() { const track = document.querySelector('#scroller-track'); const setting = document.querySelector('#scroller-setting'); if (!track || !setting) return; const vw = v => window.innerWidth * (v / 100); let ticking = false; function computeAndApply() { const rect = track.getBoundingClientRect(); const winH = window.innerHeight; const y = -rect.top; const startY = vw(15); const endY = (rect.height - winH); const span = Math.max(endY - startY, 1); const raw = (y - startY) / span; const p = Math.min(Math.max(raw, 0), 1); const x = -vw(200) * p; setting.style.transform = `translateX(${x}px)`; } function onScroll() { if (ticking) return; ticking = true; requestAnimationFrame(() => { computeAndApply(); ticking = false; }); } // kick things off and keep fresh on resize/font load/lazy images window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('resize', onScroll); window.addEventListener('orientationchange', onScroll); document.addEventListener('DOMContentLoaded', onScroll); window.addEventListener('load', onScroll); if (document.fonts?.ready) document.fonts.ready.then(onScroll); document.addEventListener('lazyloaded', e => { if (e.target.closest && e.target.closest('#scroller-track')) onScroll(); }); } // Only initialize if screen is larger than 767px if (window.innerWidth > 767) { initScroller(); } // Handle live resize crossing the threshold window.addEventListener('resize', () => { const existing = document.querySelector('#scroller-setting'); if (window.innerWidth > 767 && !existing.dataset.scrollerActive) { initScroller(); existing.dataset.scrollerActive = "true"; } else if (window.innerWidth <= 767 && existing) { existing.style.transform = ''; existing.dataset.scrollerActive = ""; window.removeEventListener('scroll', null); } }); })(); jQuery(function ($) { // SELECTORS MATCH YOUR MARKUP const $section = $('.hero-side-scroller'); // scroll region const $camera = $('#hero-scroller-camera'); // sticky container (pinned) const $track = $('#hero-scroller-setting'); // element to translate const $slides = $track.children('.elementor-element.e-child'); if (!$section.length || !$track.length) return; // Webflow-like keyframes (progress 0..1 -> X in vw) const frames = [ { p: 0.0, x: 0 }, // 0% -> 0vw { p: 0.35, x: 0 }, // 35% -> 0vw { p: 0.36, x: -100 }, // 36% -> -100vw { p: 0.64, x: -100 }, // 50% hold { p: 0.65, x: -200 }, // 65% -> -200vw { p: 0.66, x: -200 } // 66% hold ]; const clamp = (v, a, b) => Math.min(b, Math.max(a, v)); function interpX(t) { if (t = frames[frames.length - 1].p) return frames[frames.length - 1].x; for (let i = 0; i = a.p && t <= b.p) { const span = (b.p - a.p) || 1e-6; const k = (t - a.p) / span; // linear (Webflow “Linear (None)”) return a.x + (b.x - a.x) * k; } } return frames[frames.length - 1].x; } function layout() { const vw = window.innerWidth; const vh = window.innerHeight; const n = Math.max(1, $slides.length); // Give enough vertical distance to scrub; 1 viewport per slide feels right $section.css('height', (vh * n) + 'px'); // Prevent wrapping; track = N * vw $track.css('width', (n * vw) + 'px'); // Ensure camera is full-viewport tall $camera.css({ height: vh + 'px' }); } let ticking = false; function onScroll() { if (!ticking) { ticking = true; requestAnimationFrame(update); } } function update() { ticking = false; const vh = window.innerHeight; const start = $section.offset().top; const end = start + $section.outerHeight() - vh; const y = window.pageYOffset || document.documentElement.scrollTop || 0; const t = clamp((y - start) / Math.max(1, (end - start)), 0, 1); // 0..1 const xVW = interpX(t); // -200..0 (vw) $track.css('transform', 'translate3d(' + xVW + 'vw, 0, 0)'); } // init + listeners window.addEventListener('scroll', onScroll, { passive: true }); $(window).on('resize orientationchange', function () { layout(); update(); }); layout(); update(); }); (function () { // --- load GSAP + ScrollTrigger if they aren't present --- function load(src){return new Promise((ok,err)=>{var s=document.createElement('script');s.src=src;s.onload=ok;s.onerror=err;document.head.appendChild(s);});} async function ensureGSAP(){ if(!window.gsap){ await load('https://cdn.jsdelivr.net/npm/gsap@3/dist/gsap.min.js'); } if(!window.ScrollTrigger){ await load('https://cdn.jsdelivr.net/npm/gsap@3/dist/ScrollTrigger.min.js'); } gsap.registerPlugin(ScrollTrigger); } function initReveals(){ const els = document.querySelectorAll('.reveal-in'); // the second selector is a fallback if(!els.length) return; els.forEach(el => { gsap.set(el, { transformOrigin: '50% 50%', willChange: 'transform' }); // Scroll-triggered reveal (scrub ties it to scroll; set scrub:false for a 1-shot enter) gsap.fromTo(el, { scale: 0.85, autoAlpha: 0 }, { scale: 1, autoAlpha: 1, ease: 'power2.out', duration: 0.8, scrollTrigger: { trigger: el.closest('.elementor-element') || el, start: 'top 70%', end: 'top 30%', scrub: true, // make the reveal follow the scroll // toggleActions: 'play none none reverse' // use this instead of scrub if you prefer non-scrub } } ); }); // refresh on layout changes so timings stay accurate with your scroller const refresh = () => ScrollTrigger.refresh(); window.addEventListener('resize', refresh); window.addEventListener('orientationchange', refresh); window.addEventListener('load', refresh); if (document.fonts?.ready) document.fonts.ready.then(refresh); } // kick off (t156: only load GSAP where a .reveal-in element exists) if (!document.querySelector('.reveal-in')) return; // kick off if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', async () => { await ensureGSAP(); initReveals(); }); } else { (async () => { await ensureGSAP(); initReveals(); })(); } })();