let honorSwiper; let customerSaysSwiper; let timePoint = document.querySelectorAll(".time-point div") let developList = document.querySelectorAll(".develop-content-wrapper>div") // 资质荣誉模块轮播 honorSwiper = new Swiper('.honor-swiper', { autoplay: { delay: 3000 }, slidesPerView: 5, slidesPerGroup: 5, spaceBetween: 30, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, pagination: { el: '.swiper-pagination', clickable: true, }, }) // 客户反馈模块轮播 customerSaysSwiper = new Swiper('.customer-says-swiper', { autoplay: { delay: 3000 }, }) // 首页数据跳动效果函数 function addNumber(start, end, id) { let o = document.getElementById(id); let i = start; let Interval; if (i < end) { Interval = setInterval(function () { if (end > 150) { i += 5; // 设置每次增加的动态数字,可调整 } else if (end > 80 || end <= 150) { i += 3; // 设置每次增加的动态数字,可调整 } else { i += 0.5; // 设置每次增加的动态数字,可调整 } if (i > end) { clearInterval(Interval); // 清除setInterval的time,这个方法w3c可具体查看文档 o.innerHTML = end.toLocaleString(); // 此赋值是为了避免最后一次增加过后的数据和真实数据不同 i = 0; } else { o.innerHTML = i.toLocaleString(); } }, 40); // 数据跳转的速度控制 } } // 设置数据跳动交互加载只执行一次 let funcTimes = function (fn) { let caller = true; return function () { if (caller) { caller = false fn.apply(this, arguments) } } } // 首页数据跳动交互函数 let funcData = funcTimes(function () { addNumber(0, 6, 'serviceNum'); addNumber(0, 90, 'shippingTime'); addNumber(0, 150, 'sku'); addNumber(0, 210, 'productCategory'); }) // 通过鼠标滚动位置实现动画交互 function getScrollData() { let docCurrentValue = document.documentElement.scrollTop; //这里获取滚动后 body 的 scrollTop 值。 if (docCurrentValue === 300) { funcData() } scrollPos = document.documentElement.scrollTop; //最后再把滚动后的值更新给 doc ,以便之后if比较使用。 } // 发展历程模块交互 for (let i = 0, j = timePoint.length; i < j; i++) { timePoint[i].onclick = function () { for (let i = 0; i < timePoint.length; i++) { timePoint[i].classList.remove("time-point-active") developList[i].classList.remove("develop-show", "animateFadeInUp", "animate__animated", "animate__fadeIn") } this.classList.add("time-point-active") developList[i].classList.add("develop-show", "animateFadeInUp", "animate__animated", "animate__fadeIn") } } window.onload = function () { document.querySelector(".nav-wrapper li:first-of-type").classList.add("nav-active") getScrollData() funcData() } window.onscroll = function () { getScrollData(); funcData() }