$(function () { var winW = $(window).width(); function initSwiper($target) { var mySwiper = new Swiper($target.find(".swiper-container"), { navigation: { nextEl: '.industry .icon-right', prevEl: '.industry .icon-left', }, effect: 'coverflow', //3d滑动 grabCursor: true, initialSlide: 0, centeredSlides: true, loop: true, slidesPerView: 1.18, pagination: { clickable: true, }, coverflowEffect: { rotate: 0, //设置为0 stretch: 0, depth: 200, modifier: 2, slideShadows: true }, on: { init: function (swiper) { var that = this; var h = that.width / 1.2 * 600 / 1260; if (winW > 750) { $('.swiper-3d .swiper-slide').height(h); $('.swiper-3d .swiper-container').height(h + 100); } else { var textH = 0; var curH = 0; $('.industry .con .box .bod ul li').each(function () { curH = $(this).find('.text').outerHeight(true); if (curH > textH) { textH = curH; } }) $('.swiper-3d .swiper-slide').height(h); $('.swiper-3d .swiper-container').height(h + textH); } $('.industry .con .head li').on('click', function (e) { console.log(this); e.stopPropagation(); var index = $(this).index(); that.slideToLoop(index); }) }, transitionEnd: function () { var that = this; console.log(that); console.log( $('.industry .con .box .head li')[that.realIndex-1]); $('.industry .con .box .head li').eq(that.realIndex).addClass('hover').siblings().removeClass('hover'); if (winW < 750) { var boxW = $('.industry .con .box').width(); var ulW = $('.industry .con .box ul').width(); var marL = boxW / 2 - ($('.industry .con .box li').eq(that.realIndex).position().left + $('.industry .con .box li').eq(that.realIndex).outerWidth(true) / 2); if (marL > 0) { $('.industry .con .box .head').animate({ 'marginLeft': 0 }); } else if (marL < (boxW - ulW)) { $('.industry .con .box .head').animate({ 'marginLeft': (boxW - ulW) }); } else { $('.industry .con .box .head').animate({ 'marginLeft': marL }); } } }, }, }); if (winW < 750) { var headW = 0; $('.industry .con .box .head li').each(function () { headW += $(this).outerWidth(true) + 10; }); $('.industry .con .box .head').width(headW); } // 元素被swiper删除重新添加了,把之前的事件删除了,需要重新添加懒加载 $(window).on('scroll.industryOld', function () { var scrollTop = $(window).scrollTop() + $(window).height(); var boxTop = $('.industry').offset().top; if (scrollTop > boxTop) { if ($('.industry').length > 0 && $('.industry lazyload').eq(0).hasClass('over') == false) { // $('.industry .lazyload img').lazyload({ // threshold: 100, //临界值,这个值是针对container容器的,即距离container容器视口的临界值 // failure_limit: 100, //最后一个配置属性failure_limit // event: 'scroll', //触发内部appear事件 // effect: "fadeIn", //显示方法,默认为show,也可以设置为fadeIn // container: window, // data_attribute: "original", //img元素的一个data属性,用于存放图片的真实地址 // skip_invisible: true, //忽略隐藏的img元素 // appear: function () { // var $lazyload = $(this).parents(".lazyload"); // if ($lazyload.parents(".ebg-bg").length && $lazyload.parents(".ebg-bg").data("replace") != "not") { // $lazyload.parents(".ebg-bg").css("background-image", "url(" + $(this).data("original") + ")"); // $lazyload.hide(); // } // }, //在img触发appear事件时执行的回调 // load: function () { // var $lazyload = $(this).parents(".lazyload"); // if ($lazyload.parents(".ebg-bg").length && $lazyload.parents(".ebg-bg").data("replace") != "not") {} else { // $lazyload.css({ // 'height': 'auto', // 'background': 'none' // }).addClass('over'); // } // } //在img触发load事件时执行的回调 // }); } $(".industry .con .box .bod ul li .pic img").trigger("appear"); // 处理小图标懒加载 $('.industry .con .box .bod ul li').each(function () { $(this).find('img').attr('src', $(this).find('img').attr('data-original')) }) $(window).unbind('scroll.industryOld'); } }) } $(".industry.swiper-3d").each(function () { var $this = $(this); if ($this.data("swiper-init")) { return; } $this.data("swiper-init", true); initSwiper($this) }); })