this.slides[i].classList.remove('ani-slide'); } }, transitionEnd: function() { const activeSlide = this.slides[this.activeIndex]; activeSlide.classList.add('ani-slide'); }, }, navigation: { nextEl: '.banner .next', prevEl: '.banner .prev', }, }); }, initProductsSwiper() { const productsElement = document.querySelector('#products'); if (!productsElement) return; this.swiperInstances.products = new Swiper('#products', { direction: 'horizontal', speed: 1500, slidesPerView: 4, spaceBetween: 7, autoplay: { delay: 3500, disableOnInteraction: false }, navigation: { nextEl: '#products .next', prevEl: '#products .prev', }, breakpoints: { 768: { slidesPerView: 1, spaceBetween: 20 }, } }); }, // 自定义事件绑定 bindCustomEvents() { this.bindDownClick(); this.bindWheelEvent(); }, bindDownClick() { $('.down').on('click', () => { $('body').addClass('loading'); clearTimeout(this.refreshTimer); this.refreshTimer = setTimeout(() => { if (typeof ScrollTrigger !== 'undefined') { ScrollTrigger.refresh(); } }, 500); }); }, bindWheelEvent() { $('.load').on('wheel', (e) => { if (e.originalEvent.deltaY > 0 && !this.scrollTriggered) { e.preventDefault(); this.scrollTriggered = true; $('body').addClass('loading'); setTimeout(() => { if (typeof ScrollTrigger !== 'undefined') { ScrollTrigger.refresh(); } window.scrollTo(0, 0); }, 500); } }); }, // 数字滚动效果 - 修复重复触发问题 handleScroll() { // 如果已经触发过,直接返回 if (this.numberCountingStarted) return; const numberSection = $(".i-product .wrap-list"); if (!numberSection.length) return; const scrollPosition = $(window).scrollTop(); const triggerPoint = numberSection.offset().top - $(window).height(); // 当元素进入视窗时触发 if (scrollPosition > triggerPoint) { this.startNumberCounting(); // 标记为已触发,避免重复执行 this.numberCountingStarted = true; // 移除滚动监听,使用绑定后的方法引用 $(window).off('scroll', this.boundHandleScroll); } }, startNumberCounting() { if (this.numberCountingStarted) return; if (typeof CountUp === 'undefined') { console.warn('CountUp not loaded'); return; } const options = { useEasing: true, useGrouping: false, separator: ',', decimal: '.' }; try { // 使用实际的数据值,而不是硬编码 const number1Value = parseInt($("#number1").text()) || 100; const number2Value = parseInt($("#number2").text()) || 200; const number3Value = parseInt($("#number3").text()) || 300; const number1 = new CountUp("number1", 0, number1Value, 0, 3, options); const number2 = new CountUp('number2', 0, number2Value, 0, 3, options); const number3 = new CountUp('number3', 0, number3Value, 0, 3, options); if (number1 && !number1.error) number1.start(); if (number2 && !number2.error) number2.start(); if (number3 && !number3.error) number3.start(); // 标记为已执行 this.numberCountingStarted = true; } catch (error) { console.error('CountUp initialization failed:', error); } }, // 清理资源 destroy() { window.removeEventListener('resize', this.handleResize); // 使用绑定后的方法引用移除事件监听 $(window).off('scroll', this.boundHandleScroll); // 清理Swiper实例 Object.values(this.swiperInstances).forEach(swiper => { if (swiper && typeof swiper.destroy === 'function') { swiper.destroy(); } }); // 清理GSAP时间线 this.masterTLs.forEach(tl => { if (tl && typeof tl.kill === 'function') { tl.kill(); } }); // 重置状态 this.numberCountingStarted = false; this.scrollTriggered = false; } }; // 初始化应用 App.init(); // 暴露到全局作用域(可选) window.App = App;