$(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) } } })