$(function () { window.addEventListener("resize", () => { console.log($(".global-nav").height()); $(".index-product-item-img").css( "height", $(".index-product-item-img").width() ); }); var windowWidth = $(window).width() + getScrollbarWidth(); // 窗口宽度 var scrollTop = $(window).scrollTop(); // 当页面滚动时 function headScroll() { // console.log(scrollTop); if (scrollTop > 100) { $(".global-nav").addClass("scroll-top"); } else { $(".global-nav").removeClass("scroll-top"); } } headScroll(); // 监听页面滚动长度 $(window).scroll(function () { scrollTop = $(window).scrollTop(); headScroll(); }); $(".suspend .code-item .logo").mouseenter(function() { $(this).next().removeClass("popup-active").addClass("popup-code-active"); }); $(".suspend .text-item .logo").mouseenter(function () { $(this).next().addClass("popup-active"); }); $(".suspend .item").mouseleave(function () { $($(this).children()[1]) .removeClass("popup-active") .removeClass("popup-code-active"); // .stop().slideUp() }); $(".zhiding").click(function () { const currentY = window.scrollY; scrollAnimation(currentY, 0); }); $(".nav-hide-left-item-product").mouseenter(function () { $(this) .addClass("nav-hide-left-item-active") .siblings() .removeClass("nav-hide-left-item-active"); console.log($(this).index()); $($(".nav-hide-center-list")[$(this).index() - 1]) .addClass("nav-hide-center-list-show") .siblings() .removeClass("nav-hide-center-list-show"); $($(".product-nav-hide-right")[$(this).index() - 1]) .addClass("product-nav-hide-right-active") .siblings() .removeClass("product-nav-hide-right-active"); }); $(".nav-hide-center-item").mouseenter(function () { $(this) .addClass("nav-hide-center-item-active") .siblings() .removeClass("nav-hide-center-item-active"); $( $($(".product-nav-hide-right")[$(this).attr("type") - 0]).find( ".nav-hide-right-box" )[$(this).index()] ) .addClass("nav-hide-right-box-active") .siblings() .removeClass("nav-hide-right-box-active"); }); const slideleft = { distance: "100%", duration: 2000, origin: "left", opacity: null, scale: 0.6, }; const slideright = { distance: "100%", duration: 2000, origin: "right", opacity: null, scale: 0.6, }; const slidedown = { distance: "100%", duration: 2000, origin: "bottom", opacity: null, scale: 0.6, }; if (windowWidth > 768) { ScrollReveal().reveal(".slide-left", slideleft); ScrollReveal().reveal(".slide-right", slideright); ScrollReveal().reveal(".slide-down", slidedown); } function scrollAnimation(currentY, targetY) { // 计算需要移动的距离 let needScrollTop = targetY - currentY; let _currentY = currentY; setTimeout(() => { // 一次调用滑动帧数,每次调用会不一样 const dist = Math.ceil(needScrollTop / 10); _currentY += dist; window.scrollTo(_currentY, currentY); // 如果移动幅度小于十个像素,直接移动,否则递归调用,实现动画效果 if (needScrollTop > 10 || needScrollTop < -10) { scrollAnimation(_currentY, targetY); } else { window.scrollTo(_currentY, targetY); } }, 1); } });