$(function () { // var swiper1 = new Swiper(".Swiper1", { // loop: false, // grabCursor: true, // speed: 1000, // navigation: { // nextEl: ".next1", // prevEl: ".prev1", // }, // pagination: { // el: '.one', // type: 'custom', // renderCustom: function (swiper, current, total) { // var dangqian = document.querySelector(".dangqian") // var zongshu = document.querySelector(".zongshu") // if (current <= 9) { // current = "0" + current // } else { // current = current // } // if (total <= 9) { // total = "0" + total // } else { // total = total // } // dangqian.innerText = current // zongshu.innerText = total // } // }, // lazy: { // loadPrevNext: true, // }, // on: { // init: function () { // swiperAnimateCache(this); //隐藏动画元素 // swiperAnimate(this); //初始化完成开始动画 // }, // slideChangeTransitionEnd: function () { // swiperAnimate(this); //每个slide切换结束时也运行当前slide动画 // } // } // }); var select = $('.change .changeNav'); select.click(function () { let $this = $(this); $this.addClass('active'); $this.siblings().removeClass('active'); // swiper1.slideTo($this.index(), 1000, true); }) var mySwiper = new Swiper('.swiper', { direction: 'horizontal', // 垂直切换选项 // loop: true, // 循环模式选项 // 如果需要分页器 pagination: { el: '.swiper-pagination1', type: 'custom', clickable: true, bulletClass: 'swiper-box', bulletActiveClass: 'active', // renderCustom: function (swiper, current, total) { // var area = $('.swiper-box') // if (current) { // area.each(function (i) { // area.removeClass('active'); // }) // area.eq(current - 1).addClass('active'); // } // } }, }); //鼠标滑过pagination控制swiper切换 for (i = 0; i < $('.swiper-box').length; i++) { $('.swiper-box')[i].index = i $('.swiper-box')[i].onmouseover = function () { mySwiper.slideTo(this.index); }; } //如果你开启了clickable,还可以这样 for (i = 0; i < mySwiper.pagination.bullets.length; i++) { mySwiper.pagination.bullets[i].onmouseover = function () { this.click(); }; } if ($(window).width() < 1004) { for (j = 0; j < $('.swiper-box').length + 1; j++) { var w = $('.swiper-pagination1').width(); var Cw = $('.swiper-box').width(); w = Cw * j / 10; $('.swiper-pagination1').css('width', w + 'rem') console.log(j) console.log(w) console.log(Cw) } } })