$require(['swiper'], function () { var honorContent = new Swiper('.p_honor_content', { slidesPerView: 1, watchSlidesVisibility: true, // 闃叉涓嶅彲鐐瑰嚮 initialSlide: 0, observer: true, //淇敼swiper鑷繁鎴栧瓙鍏冪礌鏃讹紝鑷姩鍒濆鍖杝wiper observeParents: true, roundLengths: true, watchSlidesProgress: true, navigation: { nextEl: '.p_Honormain .swiper-button-next', prevEl: '.p_Honormain .swiper-button-prev', }, breakpoints: { 320: { // 320鍒嗚鲸鐜囦互涓 slidesPerView: 2, }, 768: { // 768鍒嗚鲸鐜囦互涓 slidesPerView: 4, }, 1280: { slidesPerView: 6, // 銆愭爣娉ㄧ殑浣嶇疆鍦ㄨ繖閲屻€戝垎绫诲鐨勮瘽锛屽彲浠ヨ缃?涓紝鍒嗙被灏戠殑璇濓紝鍙互鏍规嵁鍒嗙被鏁伴噺鏉ュ畾锛屽锛歴lidesPerView: 3 } }, on: { init: function (swiper) { addSwiperList(); }, slideChangeTransitionStart: function () { handleClickSlide(this.activeIndex); }, slideChangeTransitionEnd: function () { handleClickSlide(this.activeIndex); }, touchEnd: function () { handleClickSlide(this.activeIndex); }, }, }); function handleClickSlide(index) { honorContent.slideTo(index, 1000, false); $('.p_honorListCenter .HonorList').eq(index).addClass('active'); $('.p_honorListCenter .HonorList').eq(index).siblings().removeClass('active'); } function addSwiperList() { var visibleList = $('.p_honor_content .swiper-slide-visible').length; for (var i = 0; i < visibleList; i++) { console.log(visibleList) $('.p_honor_content .swiper-wrapper').append('

') } $('.p_honorListCenter .HonorList').eq(0).addClass('active'); } $('.Honorcategory').each(function (i) { $(this).attr('data-num', i) }); $('.Honorcategory').click(function (i) { var index = $(this).attr('data-num') honorContent.slideTo(index, 1000, false); $('.p_honorListCenter .HonorList').eq(index).addClass('active'); $('.p_honorListCenter .HonorList').eq(index).siblings().removeClass('active'); }); })