$require(['swiper'], function () { var honorContent = new Swiper('.p_honor_content', { slidesPerView: 1, watchSlidesVisibility: true, // 防止不可点击 initialSlide: 0, observer: true, //修改swiper自己或子元素时,自动初始化swiper 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, // 【标注的位置在这里】分类多的话,可以设置6个,分类少的话,可以根据分类数量来定,如:slidesPerView: 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'); }); })