"use strict"; if ($(".banner video").length && !isMobile) { $(".banner video").each(function () { var slide = $(this).parents(".swiper-slide"); var index = slide.index(); $(this).attr("id", "video" + index); var bannerVideo = videojs($(this).attr("id")); // bannerVideo.play(); slide.data("video", bannerVideo); bannerVideo.on("ended", function () { goToSwiper(index + 1); }); }); } else { $(".banner video").remove(); } var p5bgVideo; if (!isMobile) { p5bgVideo = videojs("p5bg"); p5bgVideo.play(); } else { $("#p5bg").remove(); } $(".header").addClass("fixed"); var homeBannerTimer = undefined; function observeNextSwiper(index) { var slides = $(".banner .swiper-container .swiper-slide"); if (slides.eq(index).find(".video").length === 0) { homeBannerTimer = setTimeout(function () { goToSwiper(index + 1); // 图片轮播切换时间间隔 }, 6500); } else if (slides.eq(index).data("video")) { slides.eq(index).data("video").play(); } } function goToSwiper(index) { var slides = $(".banner .swiper-container .swiper-slide"); if (index > slides.length - 1) { index = 0; } clearTimeout(homeBannerTimer); slides.each(function () { if (slides.eq(index).data("video")) { slides.eq(index).data("video").pause(); } }); if (slides.eq(index).data("video")) { slides.eq(index).data("video").play(); } $(".banner .swiper-pagination .swiper-pagination-bullet").eq(index).addClass("swiper-pagination-bullet-active").siblings().removeClass("swiper-pagination-bullet-active"); (homeSwiper.slideTo || homeSwiper.swipeTo)(index); observeNextSwiper(index); } // 首页视频文字轮播 // var homeBannerText = $('body[data-page="index"] .banner .banner-text'); // var homeBannerInterval = parseInt(homeBannerText.attr("data-interval"), 10); // setInterval(changeBannerText, homeBannerInterval); // function changeBannerText() { // var texts = homeBannerText.find("> div"); // var active = homeBannerText.find("> div.active"); // if (active.next().length) { // texts // .eq(active.index() + 1) // .addClass("active") // .siblings() // .removeClass("active"); // } else { // texts.eq(0).addClass("active").siblings().removeClass("active"); // } // } setBannerVideo(); // 首页轮播 var homeSwiper; if ($(".banner .swiper-container").length && !isMobile) { homeSwiper = new (window.Swiper3 || Swiper)(".banner .swiper-container", { // pagination: ".banner .swiper-pagination", // loop: true, grabCursor: true, effect: "fade", // paginationClickable: true, // autoplay: 6500, speed: 800 }); $(".banner .swiper-container .swiper-slide").each(function (index) { var item = $(''); $(".banner .swiper-pagination").append(item); item.on("click", function () { goToSwiper($(this).index()); }); if (index === 0) { item.addClass("swiper-pagination-bullet-active"); } }); observeNextSwiper(0); } // 首页移动端轮播 if (window.Swiper3) { $(".mobile-banner").css({ height: $(window).height() }); var swiper = new Swiper3("#home-banner-swiper", { pagination: ".mobile-banner .swiper-pagination", paginationClickable: ".mobile-banner .swiper-pagination", spaceBetween: 0, effect: "fade", autoplayDisableOnInteraction: false, autoplay: 5000, speed: 600, loop: true }); } // 设置banner video $(window).on("scroll", setBannerVideo); $(window).on("resize", setBannerVideo); setBannerVideo(); setTimeout(function () { setBannerVideo(); }); function setBannerVideo() { var ww = $(window).width(); var hh = $(window).height(); var video = $('body[data-page="index"] .video'); var width = 1936; var height = 624; // if (ww < 1200) { // ww = 1200; // } width = hh / height * width; if (width < ww) { width = ww; } // console.log(ww, width); if (/MSIE/g.test(navigator.userAgent)) { video.outerWidth(width); // video.find(".video-element").css({ // left: (width - ww) / 2 // }); } if (homeSwiper) { homeSwiper.resizeFix && homeSwiper.resizeFix(); homeSwiper.update && homeSwiper.update(); } } // test var pageIndex = 0; var prePageIndex; var scrolling = false; var scrollingSt; var parts = $(".parts .part"); if (!isMobile) { var debounceNextPage; var debouncePrevPage; var prevY; var startY; var endY; (function () { var setPart = function setPart() { $(".parts").height($(window).height()); parts.height($(window).height()); var scale = $(window).width() / 2560; if (scale > 1) { scale = 1; } $(".part__box").css({ top: -$(window).height() * pageIndex }); ifBlack(); }; var ifBlack = function ifBlack() { var partCount = $(".parts .part").length; if ($(".parts .part").eq(pageIndex).hasClass("header-is-white")) { $(".header, .mobile-header").addClass("white"); $(".part-pagination").removeClass("white"); } else { $(".header, .mobile-header").removeClass("white"); $(".part-pagination").addClass("white"); } if (pageIndex === 0 || pageIndex === partCount - 1) { $(".part-pagination").addClass("hide"); } else { $(".part-pagination").removeClass("hide"); } $(".part-pagination__count > div").eq(0).html("0" + (pageIndex + 1)); $(".part-pagination__count > div").eq(2).html("0" + (partCount - 1)); if ($(".part-pagination__dot > div").length === 0) { for (var index = 0; index < partCount - 1; index++) { var dot = $("
"); $(".part-pagination__dot").append(dot); dot.on("click", function () { prePageIndex = pageIndex; pageIndex = $(this).index(); jumpPage(); }); } } $(".part-pagination__dot > div").eq(pageIndex).addClass("active").siblings().removeClass("active"); }; var jumpPage = function jumpPage() { scrolling = true; clearTimeout(scrollingSt); scrollingSt = setTimeout(function () { scrolling = false; }, 400); if (pageIndex === 1 && prePageIndex !== parts.length - 1) { $("*[count-up-to-p]").each(function () { $(this).html($(this).attr("count-up-to-p")); if ($(this).data("countup")) { $(this).data("countup").pauseResume(); } // setTimeout(() => { // const to = parseInt($(this).attr("count-up-to-p")); window.counterUp["default"](this, { duration: 1500, delay: 50 }); // const countUp = new CountUp(this, to, { // separator: "", // }); // $(this).data("countup", countUp); // if (!countUp.error) { // countUp.start(); // } else { // console.error(countUp.error); // } // }, 50); }); } if (pageIndex === parts.length - 1) { $(".part__box").stop(true).animate({ top: -$(window).height() * (pageIndex - 1) - $(".footer").outerHeight() - $(".stock").outerHeight() }, 400, function () { updateAnimate(); }); } else { $(".part__box").stop(true).animate({ top: -$(window).height() * pageIndex }, 400, function () { updateAnimate(); }); } ifBlack(); updatePageAnimate(); if (pageIndex === 4) { p5bgVideo.play(); } }; var nextPage = function nextPage() { var isClick = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; if (pageIndex < parts.length - 1 && (!scrolling || isClick)) { prePageIndex = pageIndex; pageIndex++; jumpPage(); } }; var prevPage = function prevPage() { var isClick = arguments.length <= 0 || arguments[0] === undefined ? false : arguments[0]; if (pageIndex > 0 && (!scrolling || isClick)) { prePageIndex = pageIndex; pageIndex--; jumpPage(); } }; var updatePageAnimate = function updatePageAnimate() { if (pageIndex === 0 || pageIndex === parts.length - 1 || prePageIndex === parts.length - 1) { setTimeout(function () { updateAnimate(); }, 50); return; } setTimeout(function () { $(".part").eq(pageIndex).find(".show-in, .fade-in, .blur-in, .scale-in, .fade-in-up, .fade-in-left, .fade-in-right, .fade-in-down").each(function () { $(this).removeClass("show").attr("data-faded", ""); }); }, 50); setTimeout(function () { updateAnimate(); }, 500); }; $(window).on("resize", function () { setPart(); }); setPart(); debounceNextPage = $.debounce(150, nextPage); debouncePrevPage = $.debounce(150, prevPage); prevY = false; $(document).on("mousewheel", function (event) { if (!$('.opening.loaded').length) return; var y = event.deltaY; if (y > 0) { if (prevY !== false && (isMac ? prevY < y : prevY <= y)) { debouncePrevPage(); } } if (y < 0) { if (prevY !== false && (isMac ? prevY > y : prevY >= y)) { debounceNextPage(); } } prevY = y; }); $(document).on("keyup", function (e) { if (e.keyCode === 38) { prevPage(true); } if (e.keyCode === 40) { nextPage(true); } }); $(".parts").on("touchstart", function (e) { if ($(e.target).hasClass("prev") || $(e.target).hasClass("next") || $(e.target).attr("href")) {} else { e.preventDefault(); } startY = e.originalEvent.touches[0].pageY; endY = startY; }); $(".parts").on("touchmove", function (e) { endY = e.originalEvent.touches[0].pageY; }); $(".parts").on("touchend", function (e) { if (startY - endY > 30) { nextPage(); } if (startY - endY < -30) { prevPage(); } }); $(".controls .prev").click(function () { prevPage(true); }); $(".controls .next").click(function () { nextPage(true); }); if (isMobile) { $("body[data-page=index] .parts .part.p1 .next").hammer().on("tap", function () { nextPage(true); }); } else { $("body[data-page=index] .parts .part.p1 .next").click(function () { nextPage(true); }); } })(); } else { $("*[count-up-to-p]").each(function () { $(this).html($(this).attr("count-up-to-p")); if ($(this).data("countup")) { $(this).data("countup").pauseResume(); } window.counterUp["default"](this, { duration: 1500, delay: 50 }); }); } // p3 轮播 if (!isMobile) { var _p3Swiper = new (window.Swiper3 || Swiper)(".p3 .swiper-container", { // loop: true, grabCursor: true, slidesPerView: isMobile ? "auto" : 5, spaceBetween: 0, nextButton: ".p3 .controls .swiper-next", prevButton: ".p3 .controls .swiper-prev", // freeMode: true, // autoplay: 6500, speed: isMobile ? 300 : 900, slidesPerGroup: isMobile ? 1 : 5, onSlideChangeStart: function onSlideChangeStart(swiper) { console.log(swiper.activeIndex); var min = 390; if (window.innerWidth <= 1800) { min = 330; } if (window.innerWidth <= 1400) { min = 250; } $(".parts .part.p3 .swiper-container").css("background-position", "-" + Math.min(swiper.activeIndex * 100, min) + "px 0"); $('.p3 .swiper-container .swiper-slide').removeClass('visible'); for (var index = swiper.activeIndex; index < swiper.activeIndex + 5; index++) { $('.p3 .swiper-container .swiper-slide').eq(index).addClass('visible'); } } }); $('.p3 .swiper-container .swiper-slide').removeClass('visible'); for (var index = 0; index < 5; index++) { $('.p3 .swiper-container .swiper-slide').eq(index).addClass('visible'); } } else { $('.p3 .swiper-container .swiper-wrapper').width($('.p3 .swiper-container .swiper-wrapper .swiper-slide').length * 40 + 'vw'); } if (!window.Swiper3) { $(".p3 .controls .swiper-next").on("click", function () { p3Swiper.slideNext && p3Swiper.slideNext(); p3Swiper.swipeNext && p3Swiper.swipeNext(); }); $(".p3 .controls .swiper-prev").on("click", function () { p3Swiper.slidePrev && p3Swiper.slidePrev(); p3Swiper.swipePrev && p3Swiper.swipePrev(); }); } // p4 var p4Swiper = new (window.Swiper3 || Swiper)(".p4 .swiper-container", { loop: true, grabCursor: true, // freeMode: true, autoplay: 6500, speed: isMobile ? 300 : 600, pagination: ".p4 .swiper-pagination", paginationClickable: true }); // p5 $(".p5 .swiper-total > span").eq(2).html("0" + $(".p5 .swiper-container .swiper-slide").length); var p5Swiper = new (window.Swiper3 || Swiper)(".p5 .swiper-container", { loop: isMobile ? false : true, initialSlide: isMobile ? 1 : 0, grabCursor: true, // freeMode: true, // autoplay: 6500, speed: isMobile ? 300 : 900, slidesPerView: "auto", loopedSlides: isMobile ? 1 : 8, nextButton: ".p5 .controls .swiper-next", prevButton: ".p5 .controls .swiper-prev", // slidesPerView: 2, onSlideChangeStart: function onSlideChangeStart(swiper) { $(".p5 .swiper-total > span").eq(0).html("0" + (swiper.activeIndex + 1)); } }); if (!window.Swiper3) { $(".p5 .controls .swiper-next").on("click", function () { p5Swiper.slideNext && p5Swiper.slideNext(); p5Swiper.swipeNext && p5Swiper.swipeNext(); }); $(".p5 .controls .swiper-prev").on("click", function () { p5Swiper.slidePrev && p5Swiper.slidePrev(); p5Swiper.swipePrev && p5Swiper.swipePrev(); }); }