Swiper Slider is creating blank spaces after last slide

做~自己de王妃 提交于 2020-05-15 05:49:06

问题


I'm using Swiper Slider for a hybrid app i'm creating using Phonegap with Framework 7.

Each slide is made with dynamic content that is being brought through an Ajax call.

The problem is that i have two Sliders in the same page, and when i reach the last slide on both of them, a huge blank space starts appearing and the more we slide with our finger, the more blank space it will create.

I will leave here some prints and the relevant bits of code.

My HTML File:

    <div class="ementa-sobre pl30 mt60">

         <h3 class="titulo-v1">Ementa <div class="circulo-pequeno"></div> <span class="info-complementar-titulo" id="numero-pratos"></span></h3>

        <div class='swiper-container swiper-ementa-home'>
              <div class='swiper-wrapper' id="slider-ementa-home">
              </div>
        </div>


    </div>



 <div class="eventos-sobre pl30 mt60">

          <h3 class="titulo-v1">Eventos <div class="circulo-pequeno"></div> <span class="info-complementar-titulo" id="numero-eventos"></span></h3>

          <div class='swiper-container swiper-eventos-home'>
              <div class='swiper-wrapper' id="slider-eventos-home">
              </div>
          </div>


</div>

My JS File:

myApp.onPageInit('home', function (page) {


    $(document).ready(function()
    {

var ajaxurl3="myurl.php";
        $.ajax({
            type: "POST",
            url: ajaxurl3,
            success: function(data) {
                $.each(data, function(i, field){
                    var id=field.id_categoria;
                    var nomeCategoria=field.nome_categoria;
                    var imgCategoria=field.img_categoria;
                    var string = "<div class='swiper-slide' style='background-image:url(https://pizzarte.com/app/img/ementa/"+imgCategoria+")'><a href='pratos.html?idcat="+id+"&cat="+nomeCategoria+"'><p>"+nomeCategoria+"</p></a></div>";
                    $("#slider-ementa-home").append(string);

                })
            },
            complete: function (data) {
                var mySwiper2 = myApp.swiper('.swiper-ementa-home', {
                    spaceBetween: 15
                  });
               }
        });



        var ajaxurl4="myurl2.php";
        $.ajax({
            type: "POST",
            url: ajaxurl4,
            success: function(data) {
                $.each(data, function(i, field){
                    var id=field.id_evento;
                    var nomeEvento=field.nome_evento;
                    var imgEvento=field.img_evento;
                    var string = "<div class='swiper-slide' style='background-image:url(https://pizzarte.com/app/img/eventos/"+imgEvento+")'><a href='eventos.html?idcat="+id+"&cat="+nomeEvento+"'><p>"+nomeEvento+"</p></a></div>";
                    $("#slider-eventos-home").append(string);

                })
            },
            complete: function (data) {
                var mySwiper3 = myApp.swiper('.swiper-eventos-home', {
                    spaceBetween: 15
                  });
               }
        });


 });
})

Prints:

  • When page loads (everything is fine): https://gyazo.com/42094ad145607579572eb550a2d22d28

  • Scrolling to the last slide (lots of blank space): https://gyazo.com/64f5ec3b4d9c2e1f77357d2a040ea153

  • If we continue to scroll (if we keep scrolling, it will keep adding blank space): https://gyazo.com/f9e1be36eabbcafdd8767b05a29d2259

Any idea what's going on?


回答1:


As demkovych said (here, dublicate), add:

slidesPerView: 'auto'



回答2:


In your Swiper Initialization portion, use slidesOffsetAfter: 0, See bellow example for more details:

var swiper = new Swiper('.swiper-container', { slidesPerView: 3, spaceBetween: 30, slidesOffsetAfter:0, freeMode: true, pagination: { el: '.swiper-pagination', clickable: true, }, });

来源:https://stackoverflow.com/questions/50648049/swiper-slider-is-creating-blank-spaces-after-last-slide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!