| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- (function () {
- var modal = document.getElementById('showProductVideoModal');
- if (modal) {
- var player = modal.querySelector('.show-product-video-modal__player');
- var openButton = document.querySelector('.js-product-video-open');
- var closeTriggers = modal.querySelectorAll('[data-product-modal-close]');
- function closeModal() {
- modal.hidden = true;
- if (player) {
- player.pause();
- player.removeAttribute('src');
- player.load();
- }
- document.body.classList.remove('is-product-video-open');
- }
- if (openButton && player) {
- openButton.addEventListener('click', function () {
- var src = openButton.getAttribute('data-video');
- if (!src) return;
- player.setAttribute('src', src);
- modal.hidden = false;
- document.body.classList.add('is-product-video-open');
- player.play().catch(function () {});
- });
- }
- closeTriggers.forEach(function (node) {
- node.addEventListener('click', closeModal);
- });
- document.addEventListener('keydown', function (event) {
- if (event.key === 'Escape' && !modal.hidden) {
- closeModal();
- }
- });
- }
- var stageThreeSections = document.querySelectorAll('.js-spx-stage-three');
- var stageNineSections = document.querySelectorAll('.js-stage-nine');
- var stageSixSliders = document.querySelectorAll('.js-stage-six-slider');
- var stageEightTabs = document.querySelectorAll('.js-stage-eight-tabs');
- var stageTenSections = document.querySelectorAll('.js-stage-ten');
- function clamp(value, min, max) {
- return Math.min(Math.max(value, min), max);
- }
- function updateStageThreeState() {
- stageThreeSections.forEach(function (section) {
- var rect = section.getBoundingClientRect();
- var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
- var stickyBlock = section.querySelector('.spx-stage-three-copy-switch');
- var titleLayer = section.querySelector('.spx-stage-three-title-layer');
- var stickyHeight = stickyBlock ? stickyBlock.offsetHeight : 116;
- var titleHeight = titleLayer ? titleLayer.offsetHeight : stickyHeight;
- var titleCenterOffset = Math.max((stickyHeight - titleHeight) / 2, 0);
- var stickyTop = viewportHeight / 2 - stickyHeight / 2;
- var titleCenterY = rect.top + stickyTop + titleCenterOffset + titleHeight / 2;
- var startY = viewportHeight * 0.8;
- var availableDistance = Math.max(section.offsetHeight - stickyTop - stickyHeight - viewportHeight * 0.12, 1);
- var progress = clamp((startY - titleCenterY) / availableDistance, 0, 1);
- var fadeProgress = clamp((progress - 0.005) / 0.14, 0, 1);
- section.classList.toggle('is-text-visible', fadeProgress > 0.5);
- section.style.setProperty('--spx-stage-three-title-opacity', String(1 - fadeProgress));
- section.style.setProperty('--spx-stage-three-title-shift', (fadeProgress * -18).toFixed(2) + 'px');
- section.style.setProperty('--spx-stage-three-text-opacity', String(fadeProgress));
- section.style.setProperty('--spx-stage-three-text-shift', ((1 - fadeProgress) * 18).toFixed(2) + 'px');
- });
- }
- function updateStageNineState() {
- stageNineSections.forEach(function (section) {
- var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
- var nextStage = section.nextElementSibling;
- var fadeProgress = 0;
- if (nextStage) {
- var nextRect = nextStage.getBoundingClientRect();
- fadeProgress = clamp((viewportHeight - nextRect.top) / Math.max(viewportHeight * 0.72, 1), 0, 1);
- }
- section.style.setProperty('--spx-nine-media-opacity', (1 - fadeProgress).toFixed(4));
- var media = section.querySelector('.spx-stage-nine-media');
- if (!media) return;
- var video = media.querySelector('video');
- if (!video || video.hasAttribute('data-played')) return;
- var rect = section.getBoundingClientRect();
- var isInViewport = rect.top < viewportHeight && rect.bottom > 0;
- if (!isInViewport) return;
- video.play().then(function () {
- video.setAttribute('data-played', 'true');
- video.addEventListener('ended', function () {
- video.pause();
- }, { once: true });
- }).catch(function () {});
- });
- }
- function initStageTen() {
- stageTenSections.forEach(function (section) {
- var tabs = section.querySelectorAll('[data-stage-ten-tab]');
- var panels = section.querySelectorAll('[data-stage-ten-panel]');
- var soundEnabled = false;
- if (!tabs.length || !panels.length) return;
- function syncSoundButton(video, soundButton) {
- if (!video || !soundButton) return;
- var active = !video.muted;
- soundButton.classList.toggle('is-active', active);
- soundButton.setAttribute('aria-label', active ? '关闭声音' : '开启声音');
- soundButton.innerHTML = active
- ? '<i class="bi bi-volume-up-fill" aria-hidden="true"></i>'
- : '<i class="bi bi-volume-mute-fill" aria-hidden="true"></i>';
- }
- function syncVideo(panel, active) {
- var video = panel.querySelector('.spx-stage-ten-video');
- var soundButton = panel.querySelector('[data-stage-ten-sound]');
- if (!video) return;
- if (active) {
- video.muted = !soundEnabled;
- syncSoundButton(video, soundButton);
- video.play().catch(function () {});
- } else {
- video.pause();
- video.currentTime = 0;
- video.muted = true;
- syncSoundButton(video, soundButton);
- }
- }
- function setActive(index) {
- tabs.forEach(function (tab, i) {
- var active = i === index;
- tab.classList.toggle('is-active', active);
- tab.setAttribute('aria-selected', active ? 'true' : 'false');
- });
- panels.forEach(function (panel, i) {
- var active = i === index;
- panel.classList.toggle('is-active', active);
- syncVideo(panel, active);
- });
- }
- tabs.forEach(function (tab, index) {
- tab.addEventListener('click', function () {
- setActive(index);
- });
- });
- panels.forEach(function (panel) {
- var soundButton = panel.querySelector('[data-stage-ten-sound]');
- var video = panel.querySelector('.spx-stage-ten-video');
- if (!soundButton || !video) return;
- syncSoundButton(video, soundButton);
- soundButton.addEventListener('click', function () {
- soundEnabled = video.muted;
- video.muted = !soundEnabled;
- syncSoundButton(video, soundButton);
- if (video.paused) {
- video.play().catch(function () {});
- }
- });
- });
- setActive(0);
- });
- }
- function initRevealAnimations() {
- var revealNodes = document.querySelectorAll('.spx-reveal');
- if (!revealNodes.length) return;
- function revealInViewNodes() {
- var viewportHeight = window.innerHeight || document.documentElement.clientHeight;
- revealNodes.forEach(function (node) {
- if (node.classList.contains('is-visible')) return;
- var rect = node.getBoundingClientRect();
- if (rect.top <= viewportHeight * 0.92 && rect.bottom >= viewportHeight * 0.08) {
- node.classList.add('is-visible');
- }
- });
- }
- if (!('IntersectionObserver' in window)) {
- revealNodes.forEach(function (node) {
- node.classList.add('is-visible');
- });
- return;
- }
- var observer = new IntersectionObserver(function (entries) {
- entries.forEach(function (entry) {
- if (!entry.isIntersecting) return;
- entry.target.classList.add('is-visible');
- observer.unobserve(entry.target);
- });
- }, {
- threshold: 0.12,
- rootMargin: '0px 0px -6% 0px'
- });
- revealNodes.forEach(function (node) {
- observer.observe(node);
- });
- revealInViewNodes();
- window.addEventListener('load', revealInViewNodes, { once: true });
- window.addEventListener('resize', revealInViewNodes);
- window.addEventListener('scroll', revealInViewNodes, { passive: true });
- }
- function initStageEighteenModal() {
- var modal = document.getElementById('stageEighteenModal');
- if (!modal) return;
- var triggers = document.querySelectorAll('[data-stage-eighteen-trigger]');
- var panels = modal.querySelectorAll('[data-stage-eighteen-panel]');
- var closeTriggers = modal.querySelectorAll('[data-stage-eighteen-close]');
- if (!triggers.length || !panels.length) return;
- function setActivePanel(id) {
- panels.forEach(function (panel) {
- panel.classList.toggle('is-active', panel.getAttribute('data-stage-eighteen-panel') === id);
- });
- }
- function openModal(id) {
- setActivePanel(id);
- modal.hidden = false;
- document.body.classList.add('is-product-video-open');
- }
- function closeModal() {
- modal.hidden = true;
- document.body.classList.remove('is-product-video-open');
- }
- triggers.forEach(function (trigger) {
- trigger.addEventListener('click', function () {
- var id = trigger.getAttribute('data-stage-eighteen-trigger');
- if (!id) return;
- openModal(id);
- });
- });
- closeTriggers.forEach(function (node) {
- node.addEventListener('click', closeModal);
- });
- document.addEventListener('keydown', function (event) {
- if (event.key === 'Escape' && !modal.hidden) {
- closeModal();
- }
- });
- }
- if (stageThreeSections.length) {
- updateStageThreeState();
- }
- updateStageNineState();
- initStageTen();
- initRevealAnimations();
- initStageEighteenModal();
- window.addEventListener('scroll', function () {
- if (stageThreeSections.length) {
- updateStageThreeState();
- }
- updateStageNineState();
- }, { passive: true });
- window.addEventListener('resize', function () {
- if (stageThreeSections.length) {
- updateStageThreeState();
- }
- updateStageNineState();
- });
- stageSixSliders.forEach(function (slider) {
- var slides = slider.querySelectorAll('.spx-stage-six-slide');
- var dots = slider.querySelectorAll('[data-stage-six-dot]');
- var prevButton = slider.querySelector('[data-stage-six-prev]');
- var nextButton = slider.querySelector('[data-stage-six-next]');
- if (!slides.length) return;
- var activeIndex = 0;
- var timer = null;
- function setActive(index) {
- activeIndex = (index + slides.length) % slides.length;
- slides.forEach(function (slide, i) {
- slide.classList.toggle('is-active', i === activeIndex);
- slide.setAttribute('aria-hidden', i === activeIndex ? 'false' : 'true');
- });
- dots.forEach(function (dot, i) {
- var active = i === activeIndex;
- dot.classList.toggle('is-active', active);
- dot.setAttribute('aria-current', active ? 'true' : 'false');
- });
- }
- function start() {
- if (slides.length < 2) return;
- stop();
- timer = window.setInterval(function () {
- setActive(activeIndex + 1);
- }, 4200);
- }
- function stop() {
- if (timer) {
- window.clearInterval(timer);
- timer = null;
- }
- }
- dots.forEach(function (dot) {
- dot.addEventListener('click', function () {
- var index = Number(dot.getAttribute('data-stage-six-dot') || 0);
- setActive(index);
- start();
- });
- });
- if (prevButton) {
- prevButton.addEventListener('click', function () {
- setActive(activeIndex - 1);
- start();
- });
- }
- if (nextButton) {
- nextButton.addEventListener('click', function () {
- setActive(activeIndex + 1);
- start();
- });
- }
- slider.addEventListener('mouseenter', stop);
- slider.addEventListener('mouseleave', start);
- slider.addEventListener('focusin', stop);
- slider.addEventListener('focusout', start);
- setActive(0);
- start();
- });
- stageEightTabs.forEach(function (block) {
- var tabs = block.querySelectorAll('[data-stage-eight-tab]');
- var panels = block.querySelectorAll('[data-stage-eight-panel]');
- var contents = block.querySelectorAll('[data-stage-eight-content]');
- if (!tabs.length) return;
- function setActive(index) {
- tabs.forEach(function (tab, i) {
- var active = i === index;
- tab.classList.toggle('is-active', active);
- tab.setAttribute('aria-selected', active ? 'true' : 'false');
- });
- panels.forEach(function (panel, i) {
- panel.classList.toggle('is-active', i === index);
- });
- contents.forEach(function (content, i) {
- content.classList.toggle('is-active', i === index);
- });
- }
- tabs.forEach(function (tab, index) {
- tab.addEventListener('click', function () {
- setActive(index);
- });
- });
- setActive(0);
- });
- document.querySelectorAll('.js-stage-eleven').forEach(function (section) {
- var tabs = section.querySelectorAll('[data-stage-eleven-tab]');
- var panels = section.querySelectorAll('[data-stage-eleven-panel]');
- if (!tabs.length || !panels.length) return;
- function syncPanelMedia(panel, active) {
- var video = panel.querySelector('.spx-stage-eleven-video');
- if (!video) return;
- if (active) {
- video.play().catch(function () {});
- } else {
- video.pause();
- video.currentTime = 0;
- }
- }
- function setActive(index) {
- tabs.forEach(function (tab, i) {
- var active = i === index;
- tab.classList.toggle('is-active', active);
- tab.setAttribute('aria-selected', active ? 'true' : 'false');
- });
- panels.forEach(function (panel, i) {
- var active = i === index;
- panel.classList.toggle('is-active', active);
- syncPanelMedia(panel, active);
- });
- }
- tabs.forEach(function (tab, index) {
- tab.addEventListener('click', function () {
- setActive(index);
- });
- });
- setActive(0);
- });
- })();
|