/* ============================================================ 维特尔液冷 — 页面交互 滚动显现 · 指标滚动计数 · 导航状态 · 移动端菜单 ============================================================ */ (function () { "use strict"; var REDUCED = window.matchMedia("(prefers-reduced-motion: reduce)").matches; var FINE_POINTER = window.matchMedia("(hover: hover) and (pointer: fine)").matches; var MOBILE_HERO = window.matchMedia("(max-width: 768px)").matches; /* ---------- 首屏视频:移动端/减少动画模式仅显示静态海报 ---------- */ var heroMediaVideo = document.getElementById("heroMediaVideo"); if (heroMediaVideo) { if (REDUCED || MOBILE_HERO) { heroMediaVideo.pause(); heroMediaVideo.removeAttribute("autoplay"); } else { var heroVideoSource = heroMediaVideo.querySelector("source[data-src]"); if (heroVideoSource) { heroVideoSource.src = heroVideoSource.dataset.src; heroMediaVideo.load(); } var playPromise = heroMediaVideo.play(); if (playPromise && typeof playPromise.catch === "function") playPromise.catch(function () {}); } } /* 截图辅助:?shot=1 时取消首屏满高(仅用于整页验证) */ if (location.search.indexOf("shot") !== -1) { document.documentElement.classList.add("shot"); } /* ---------- 导航滚动状态 ---------- */ var nav = document.getElementById("nav"); var backToTop = document.getElementById("backToTop"); function onScroll() { nav.classList.toggle("scrolled", window.scrollY > 24); if (backToTop) backToTop.classList.toggle("is-visible", window.scrollY > window.innerHeight * 0.75); } window.addEventListener("scroll", onScroll, { passive: true }); onScroll(); if (backToTop) { backToTop.addEventListener("click", function () { window.scrollTo({ top: 0, behavior: REDUCED ? "auto" : "smooth" }); document.querySelector(".brand").focus({ preventScroll: true }); }); } /* ---------- 当前章节高亮 / URL 锚点 ---------- */ var sectionIds = ["technology", "solutions", "proof", "partners", "contact"]; var trackedSections = sectionIds.map(function (id) { return document.getElementById(id); }).filter(Boolean); var navAnchors = [].slice.call(document.querySelectorAll('.nav-links a[href^="#"], .nav-mobile a[href^="#"]')); function setActiveSection(id) { navAnchors.forEach(function (link) { var active = link.getAttribute("href") === "#" + id; link.classList.toggle("is-active", active); if (active) link.setAttribute("aria-current", "location"); else link.removeAttribute("aria-current"); }); } if (trackedSections.length) { var sectionFrame = 0; function updateActiveSection() { if (sectionFrame) return; sectionFrame = requestAnimationFrame(function () { sectionFrame = 0; var probe = window.scrollY + Math.max(120, window.innerHeight * 0.25); var current = trackedSections[0]; trackedSections.forEach(function (section) { if (section.offsetTop <= probe) current = section; }); setActiveSection(current.id); }); } window.addEventListener("scroll", updateActiveSection, { passive: true }); updateActiveSection(); } /* ---------- 移动端菜单 ---------- */ var toggle = document.getElementById("navToggle"); var mobile = document.getElementById("navMobile"); if (toggle) { toggle.addEventListener("click", function () { var open = nav.classList.toggle("open"); toggle.setAttribute("aria-expanded", open ? "true" : "false"); toggle.setAttribute("aria-label", open ? "关闭菜单" : "打开菜单"); }); mobile.querySelectorAll("a").forEach(function (a) { a.addEventListener("click", function () { nav.classList.remove("open"); toggle.setAttribute("aria-expanded", "false"); }); }); document.addEventListener("keydown", function (event) { if (event.key === "Escape" && nav.classList.contains("open")) { nav.classList.remove("open"); toggle.setAttribute("aria-expanded", "false"); toggle.setAttribute("aria-label", "打开菜单"); toggle.focus(); } }); } /* ---------- 产品路径与当前产品 ---------- */ var capList = document.querySelector(".cap-list"); var capRows = [].slice.call(document.querySelectorAll(".cap-row")); if (capList && capRows.length) { if (REDUCED) { capList.classList.add("is-traced"); } else { var capListIO = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { capList.classList.add("is-traced"); capListIO.disconnect(); } }); }, { threshold: 0.1 }); capListIO.observe(capList); } } /* ---------- 滚动显现 ---------- */ var revealEls = [].slice.call(document.querySelectorAll("[data-reveal]")); if (REDUCED) { revealEls.forEach(function (el) { el.classList.add("is-visible"); }); } else { var revealIO = new IntersectionObserver(function (entries) { entries.forEach(function (en) { if (en.isIntersecting) { en.target.classList.add("is-visible"); revealIO.unobserve(en.target); } }); }, { threshold: 0.12, rootMargin: "0px 0px -6% 0px" }); revealEls.forEach(function (el) { revealIO.observe(el); }); } /* ---------- 指标滚动计数 ---------- */ var counters = [].slice.call(document.querySelectorAll(".count")); function animateCount(el) { var target = parseFloat(el.dataset.count); var decimals = parseInt(el.dataset.decimals || "0", 10); if (REDUCED) { el.textContent = target.toFixed(decimals); return; } var start = null, dur = 1600; function step(ts) { if (!start) start = ts; var p = Math.min((ts - start) / dur, 1); var eased = 1 - Math.pow(1 - p, 4); el.textContent = (target * eased).toFixed(decimals); if (p < 1) requestAnimationFrame(step); else el.textContent = target.toFixed(decimals); } requestAnimationFrame(step); } if (REDUCED) { /* 降级:不依赖 IO,直接呈现终值 */ counters.forEach(function (el) { animateCount(el); var cell = el.closest(".kpi-cell"); if (cell) cell.classList.add("powered"); }); } else { var countIO = new IntersectionObserver(function (entries) { entries.forEach(function (en) { if (en.isIntersecting) { var cell = en.target.closest(".kpi-cell"); /* 仪表上电:先扫描线,数字随后点亮,单位与标签再延迟出现 */ if (cell) cell.classList.add("powered"); setTimeout(function () { animateCount(en.target); }, 240); countIO.unobserve(en.target); } }); }, { threshold: 0.5 }); counters.forEach(function (el) { countIO.observe(el); }); } /* ---------- 工况面板:项目阶段切换(视觉) ---------- */ document.querySelectorAll(".cond-chips").forEach(function (group) { group.querySelectorAll(".cond-chip").forEach(function (chip) { chip.addEventListener("click", function () { group.querySelectorAll(".cond-chip").forEach(function (c) { c.classList.toggle("on", c === chip); }); }); }); }); })();