$(function() { var $banner = $('.home-banner'); var lenPc = $('.swiper-container-banner .swiper-slide').length; if (lenPc > 1) { var swiperPc = new Swiper('.swiper-container-banner', { autoplay: { delay: 4600, stopOnLastSlide: false, disableOnInteraction: false, }, loop: true, initialSlide: 0, pagination: { el: '.swiper-banner-pagination-pc', clickable: true } }); } else if (lenPc == 1) { setTimeout(function() { $('.swiper-container-banner .swiper-slide').addClass('swiper-slide-active'); }, 500); } var lenWap = $('.swiper-container-banner-wap .swiper-slide').length; if (lenWap > 1) { var swiperWap = new Swiper('.swiper-container-banner-wap', { autoplay: { delay: 4600, stopOnLastSlide: false, disableOnInteraction: false, }, loop: true, initialSlide: 0, pagination: { el: '.swiper-banner-pagination', clickable: true } }); } else { setTimeout(function() { $('.swiper-container-banner-wap .swiper-slide').addClass('swiper-slide-active'); }, 500); } //初始化整屏滚动 function initScroll() { var curIndex = 0; var container = $(".main"); var sumCount = $(".main .section").length; var $window = $(window); var duration = 500; //时间控制 var aniTime = 0; var scrollFunc = function(e) { //移动端不做滚动 if (is_wap()) { curIndex = 0; setCur(); return; } //假设动画还没运行完,则return if (new Date().getTime() < aniTime + duration) { return; } e = e || window.event; var t = 0; if (e.wheelDelta) { //IE/Opera/Chrome t = e.wheelDelta; if (t > 0 && curIndex > 0) { //上滚动 movePrev(); } else if (t < 0 && curIndex < sumCount - 1) { //下滚动 moveNext(); } } else if (e.detail) { //Firefox t = e.detail; if (t < 0 && curIndex > 0) { //上滚动 movePrev(); } else if (t > 0 && curIndex < sumCount - 1) { //下滚动 moveNext(); } } }; function setCur() { aniTime = new Date().getTime(); container.css("transform", "translate3D(0, -" + (curIndex) * $window.height() + "px, 0)"); if (curIndex > 0) { $('.header-dynamic').removeClass('header-transparent'); setTimeout(function() { $('.header-dynamic .header-fixed').addClass('line'); $('.header-dynamic .header-fixed').css({ 'background': '#fff' }); }, 500) } else { $('.header-dynamic .header-fixed').removeClass('line'); $('.header-dynamic').addClass('header-transparent'); $('.header-dynamic .header-fixed').css({ 'background': 'none' }); } $(".main .section.active").removeClass('active'); $($(".main .section")[curIndex]).addClass('active'); } function moveNext() { //获取动画開始时的时间 ++curIndex; setCur(); } function movePrev() { //获取动画開始时的时间 --curIndex; setCur(); } function changeItem(type) { //移动端不做滚动 if (is_wap()) { curIndex = 0; setCur(); return; } //假设动画还没运行完,则return if (new Date().getTime() < aniTime + duration) { return; } if (type > 0 && curIndex > 0) { //上滚动 movePrev(); } else if (type == 0 && curIndex < sumCount - 1) { //下滚动 moveNext(); } } function init() { /*注冊事件*/ if (document.addEventListener) { document.addEventListener('DOMMouseScroll', scrollFunc, false); } //W3C window.onmousewheel = document.onmousewheel = scrollFunc; //IE/Opera/Chrome window.onresize = function() { setCur(); } document.body.onkeydown = function(e) { e = window.event || e; switch (e.keyCode) { case 38: //向上键 changeItem(1); break; case 40: //向下键 changeItem(0); break; default: break; } } setCur(); container.css({ "transition": "all 0.5s", "-moz-transition": "all 0.5s", "-webkit-transition": "all 0.5s" }); } init(); } initScroll(); })