查看: 3119|回复: 7
打印 上一主题 下一主题

swiper嵌套,遇到嵌套内的动画第二屏不执行问题

[复制链接]
  • TA的每日心情
    奋斗
    2017-6-6 09:42
  • 签到天数: 1 天

    [LV.1]初来乍到

    1

    主题

    6

    帖子

    77

    积分

    注册会员

    Rank: 2

    积分
    77
    跳转到指定楼层
    楼主
    发表于 2018-3-6 16:54:44 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    使用swiper做垂直切换,每屏都增加了动画,在其中一屏插入水平切换,并且每屏也都是有动画,现在遇到这么个问题:
    垂直切换动画无问题,当切换到水平swiper的时候,水平动画第一屏动画正常显示,横滑切换到第二个画面,动画消失,直接fade出现的。第三屏正常。然后向下切换后在回来,又出现该问题了。
    html如下:

    <div class="swiper-container swiper-container-h">
            <div class="swiper-wrapper">

                    <section class="swiper-slide">1</section>
                    <section class="swiper-slide">
                            <div class="swiper-container swiper-container-v">
                                    <div class="swiper-wrapper">
                                            <section class="swiper-slide"><div class="pro_tit font_hei ani" swiper-animate-effect="fadeInDown" swiper-animate-duration="0.3s" swiper-animate-delay="0.3s">动画A</div></section>
                                            <section class="swiper-slide"><div class="pro_tit font_hei ani" swiper-animate-effect="fadeInDown" swiper-animate-duration="0.3s" swiper-animate-delay="0.3s">动画B</div></section>
                                             <section class="swiper-slide"><div class="pro_tit font_hei ani" swiper-animate-effect="fadeInDown" swiper-animate-duration="0.3s" swiper-animate-delay="0.3s">动画C</div></section>
                                    </div>
                            </div>
                    </section>
                    <section class="swiper-slide">3</section>
            </div>
    </div>

    js代码如下:

    <script type="text/javascript">
    var swiperH = new Swiper('.swiper-container-h',{
            on:{
                    init: function(){
                            swiperAnimateCache(this);
                            swiperAnimate(this);
                    },
                    slideChangeTransitionEnd: function(){
                            swiperAnimate(this);
                    }
            },
            direction:"vertical",
            navigation:{
                    nextEl:'.nextPage',
            },
            effect : 'fade',
    });
    var swiperV = new Swiper('.swiper-container-v', {
            on:{
                    init: function(){
                            swiperAnimateCache(this);
                            swiperAnimate(this);
                    },
                   
                    slideChangeTransitionEnd: function(){
                            swiperAnimate(this);
                    }
            },
            pagination: {
                    el: '.swiper-pagination-v',
            },
            effect : 'fade',
    });
    </script>

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏 分享分享 分享淘帖
    回复

    使用道具 举报

  • TA的每日心情
    郁闷
    2020-4-6 13:37
  • 签到天数: 4 天

    [LV.2]偶尔看看I

    0

    主题

    35

    帖子

    126

    积分

    注册会员

    Rank: 2

    积分
    126
    沙发
    发表于 2018-3-22 16:25:01 | 只看该作者
    我也遇到了,发现当第一屏动画没有执行完就滑到第二屏,动画可以加载,说明等第一屏动画加载完第二屏其实也加载完了
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2020-3-11 17:39
  • 签到天数: 2 天

    [LV.1]初来乍到

    0

    主题

    5

    帖子

    26

    积分

    新手上路

    Rank: 1

    积分
    26
    板凳
    发表于 2020-3-10 22:56:29 | 只看该作者
    我也遇到了这样的问题,父swiper中动画执行的同时将子swiper中的动画加载完成了
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    1

    主题

    3

    帖子

    22

    积分

    新手上路

    Rank: 1

    积分
    22
    地板
    发表于 2021-9-25 18:26:02 | 只看该作者
    楼主这个问题解决了么?我也遇到了这个问题
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2020-9-22 16:12
  • 签到天数: 1 天

    [LV.1]初来乍到

    0

    主题

    6

    帖子

    13

    积分

    新手上路

    Rank: 1

    积分
    13
    5#
    发表于 2022-2-19 20:28:20 | 只看该作者
    我的嵌套代码
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2020-9-22 16:12
  • 签到天数: 1 天

    [LV.1]初来乍到

    0

    主题

    6

    帖子

    13

    积分

    新手上路

    Rank: 1

    积分
    13
    6#
    发表于 2022-2-19 20:31:08 | 只看该作者
    参考方案:

    //外面大的 swiper初始化
        const mySwiper = new Swiper ('#pageSwiper', {
          width: window.innerWidth,
          height: window.innerHeight,
          initialSlide,
          direction : 'vertical',
          effect : 'coverflow',
          lazy: {
            loadPrevNext: true,
            loadOnTransitionStart: true,
          },
          noSwiping : true,
          noSwipingClass : 'stop-swiping',
          on: {
            init: function(){
              swiperAnimateCache(this); //隐藏动画元素
              swiperAnimate(this); //初始化完成开始动画
            },
            slideChange: function(){
              if(this.activeIndex === 1) {
                swiperAnimate(gallerySwiper);   // 重点部分,这样嵌入的就可以初始化 完美展示动画了
              } else {
                swiperAnimate(this);
              }
            },
          }
        });   

    // 第二页嵌入的 swiper
        const gallerySwiper = new Swiper ('#gallerySwiper', {
          initialSlide: 0,
          loop : true,
          effect : 'fade',
          lazy: {
            loadPrevNext: true,
            loadOnTransitionStart: true,
          },
          nested:true,
          on:{
            slideChange: function(){
              //每个slide切换结束时也运行当前slide动画
              swiperAnimate(this);
            },
          },
          pagination: {
            el: '.gallery-pagination',
            type : 'custom',
            renderCustom: function (swiper, current, total) {
              const html = `<div class="swiper-dots">
                <span class="swiper-dot ${current === 1 && 'active'}"></span>
                <span class="swiper-dot ${current === 2 && 'active'}"></span>
                </div>`;
              return html;
            }
          }
        });
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    Archiver|手机版|小黑屋|Swiper中文网 ( 粤ICP备15001020号

    GMT+8, 2024-4-20 12:42 , Processed in 0.081480 second(s), 29 queries .

    Powered by Discuz! X3.2

    © 2001-2013 Comsenz Inc.

    快速回复 返回顶部 返回列表