swiper走马灯效果加自动轮播鼠标放上去暂停当前动作移除立即恢复

<div class="scroll-target">
    <div class="targr">
        <div class="swiper-container onebottm">
            <div class="swiper-wrapper">
                <div class="swiper-slide>
                    <div class="img"><img src="images/zanwei.jpg" alt=""></div>
                </div>
                <div class="swiper-slide>
                    <div class="img"><img src="images/zanwei.jpg" alt=""></div>
                </div>
                <div class="swiper-slide>
                    <div class="img"><img src="images/zanwei.jpg" alt=""></div>
                </div>
                <div class="swiper-slide>
                    <div class="img"><img src="images/zanwei.jpg" alt=""></div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
        var jointVentureSwiper = new Swiper(".onebottm", {
            slidesPerView: 1.2,
            spaceBetween: 20,
            loop: true,
            breakpoints: {
                1480: {
                    slidesPerView: 2.12,
                    spaceBetween: 20,
                },
            },
            speed: 4000,
            autoplay: {
                delay: 0, //自动切换的时间间隔
                disableOnInteraction: false,
                pauseOnMouseEnter: true, //鼠标置于swiper时暂停自动切换,鼠标离开时恢复自动切换。
                stopOnLastSlide: false,
                pauseOnMouseEnter:true,
                disableOnInteraction:false,
                disableOnInteraction: false
            },
            loopFillGroupWithBlank: true,
            normalizeSlideIndex:true,
            freeMode: true,
        });

         var jSpeed = 4000;
        var nextTransForm = '';
        var nextSpeed = 0;
        $('.onebottm').on('mouseenter', function () {
          nextTransForm = 'transform:' + $('.onebottm').find('.swiper-wrapper').eq(0).attr('style').split('transform:')[1].split(';')[0];
          var nextS = -1 * parseInt(nextTransForm.split('translate3d(')[1].split('px')[0]);
          var nowS = -1 * parseInt($('.onebottm').find('.swiper-wrapper').eq(0).css('transform').split('1, ')[2].split(',')[0]);
          nextSpeed = jSpeed * ((nextS - nowS) / $('.onebottm').find('.swiper-slide').eq(0).width());
          $('.onebottm').find('.swiper-wrapper').eq(0).attr('style', `${$('.onebottm').find('.swiper-wrapper').eq(0).attr('style').split('transform: ')[0]}transform: ${$('.onebottm').find('.swiper-wrapper').eq(0).css('transform')};transition-duration:0ms;`);
        });

        $('.onebottm').on('mouseleave', function () {
          $('.onebottm').find('.swiper-wrapper').eq(0).attr('style', `${$('.onebottm').find('.swiper-wrapper').eq(0).attr('style').split('transform: ')[0]}${nextTransForm};transition-duration:${nextSpeed}ms;`);
          jointVentureSwiper.startAutoplay();
        }); 

        $(".scroll-target .targr").hover(function(){
            $(".targr").toggleClass("cie");
        });

</script>

  • 7
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值