/* "Studio" treatment, from section 2 onwards. * * Every section is staged like a room: a light from above and a shadow on the * floor. The moving part — the bolts — belongs to each section's own core * (see netball.js), not to the ceiling: the story is that everything radiates * out from the engine at the centre. * * Section 1 is deliberately left alone — it is the title card. */ (function () { if (matchMedia('(prefers-reduced-motion: reduce)').matches) return; /* Which way are we travelling? The page is the only scroller now — the deck used to have one of its own — so watching the window is the whole story. */ var lastY = 0, goingUp = false; function watch(el, read) { (el || window).addEventListener('scroll', function () { var y = read(); goingUp = y < lastY; lastY = y; }, { passive: true }); } watch(null, function () { return window.scrollY || document.documentElement.scrollTop; }); var slides = Array.prototype.slice.call(document.querySelectorAll('.slide')); var pack = document.querySelector('.pack'); if (pack) slides.push(pack); slides.forEach(function (slide) { if (slide.id === 'hero') return; // the title card stays clean slide.classList.add('studio'); var rig = document.createElement('div'); rig.className = 'studio__rig'; rig.setAttribute('aria-hidden', 'true'); rig.innerHTML = '' + '' + '' + '' + '' + '' + ''; slide.appendChild(rig); /* information floating in the room — a handful of slow motes, built once */ var dust = rig.querySelector('.studio__dust'); for (var d = 0; d < 14; d++) { var i = document.createElement('i'); var sz = 2 + Math.random() * 4; i.style.cssText = 'left:' + (Math.random() * 100).toFixed(1) + '%;' + 'top:' + (Math.random() * 100).toFixed(1) + '%;' + 'width:' + sz.toFixed(1) + 'px;height:' + sz.toFixed(1) + 'px;' + 'animation-duration:' + (14 + Math.random() * 16).toFixed(1) + 's;' + 'animation-delay:-' + (Math.random() * 20).toFixed(1) + 's'; dust.appendChild(i); } /* entering a room: sweep the light across and settle the content */ new IntersectionObserver(function (es) { es.forEach(function (e) { if (!e.isIntersecting) { slide.classList.remove('is-entering'); return; } slide.classList.remove('is-entering'); slide.classList.toggle('is-up', goingUp); void slide.offsetWidth; // restart the animation slide.classList.add('is-entering'); }); }, { threshold: 0.45 }).observe(slide); }); })();