简体   繁体   English

BxSlider将最后一张幻灯片显示为第一张幻灯片

[英]BxSlider displayes last slide as first slide

I have created 4 sliders. 我创建了4个滑块。 Initially all 4 are hidden (display:none) so I have used this code to display the relevant slider on click of its respective category. 最初所有4个都是隐藏的(显示:无),所以我使用此代码在点击其各自的类别时显示相关的滑块。

The slider configuration. 滑块配置。

    touchEnabled: true,
    hideControlOnEnd: true,
    preloadImages: 'all',
    infiniteLoop: false,
    mode: 'horizontal',
    startSlide: 0,
    slideWidth: 300,
    minSlides: 2,
    maxSlides: 3,
    slideMargin: 10,
    pager: false,
    slideSelector: ".isotope-item",
    nextSelector: "#forefoo2_next",
    prevSelector: "#forefoo2_prev",
    nextText: '',
    prevText: '',
    onSliderLoad: function(){
        jQuery(".sliloading").hide();
    },


jQuery(window).ready(function(){
    var slider4 = jQuery('.cat_fore').bxSlider();
    var slider2 = jQuery('#cat_two').bxSlider();
    var slider3 = jQuery('.cat_three').bxSlider();
    var slider1 = jQuery('.cat_one').bxSlider();

    jQuery("#sel_cat a" ).on("click", function(){
        var current     = jQuery(this).attr("slider");
        jQuery(".sliloading").show();

        jQuery(".slider").hide();
        if( current == "cat_one"){
            slider1.reloadSlider(s1config);
        }else if(current == "cat_two"){
            slider2.reloadSlider(s2config);
        }else if(current == "cat_three"){
            slider3.reloadSlider(s3config);
        }else if(current == "cat_fore"){
            slider4.reloadSlider(s4config);
        }
   }
});

The problem is when the slider is having less then 20 slides it reverses the count of the slides that is it displayed last slide as first slide. 问题是当滑块具有少于20个幻灯片时,它会反转幻灯片的计数,该幻灯片作为第一张幻灯片显示在最后一张幻灯片上。

For slides 20 or more then 20 it works fine. 对于20或20以上的幻灯片,它可以正常工作。 I also tried different solutions listed on this link but nothing worked for me. 我也试过这个链接上列出的不同解决方案,但对我没什么用。
I tried to replicate the same example on fiddle which is working fine but on live it is still giving the same problem 我试图在小提琴上复制相同的例子,但工作正常,但在现场它仍然给出同样的问题

I think problem is in the height or some other css element which is making it start from the last slide because in fiddle the view port is small so it displayed slider first slide and also when wee try to decrease the size of the view port of the browser it also displayed slider in the right way. 我认为问题是在高度或其他一些css元素使它从最后一张幻灯片开始,因为在小提琴视图端口很小所以它显示滑块第一张幻灯片,当我们试图减小视图端口的大小时浏览器它也以正确的方式显示滑块。

I was having this problem too just recently. 我最近才遇到这个问题。 The solution is you have to put the instance of BxSlider on $(window).load() event not in $(window).ready() here's a sample. 解决方案是您必须将$(window).load()事件中的BxSlider实例放在$(window).ready()这里是一个示例。

$(window).load(function(){
            $('.bxslider').bxSlider({
                pagerCustom: '#bx-pager',
                randomStart: false,
                controls: true,
                auto: true
            });    
        });

It is important to note that the problem starts to persist once you have at least 7 slides. 重要的是要注意,一旦你有至少7张幻灯片,问题就会持续存在。

Fast solution: 快速解决方案

.bx-clone{
   display: none !important;
}

If you don't want to lose the infiniteLoop animation: 如果您不想丢失infiniteLoop动画:

   onSliderLoad: function() {
      $("YOUR_SLIDER_SELECTOR").css(
         "-webkit-transform", 
         "translate3d(-" + YOUR_SLIDER_WIDTH + "px, 0, 0)"
      );
    }

This is a chrome-only bug for me, where the "clone slide" intended for making seamless scrolling from the last slide back to the first will show first pushing the actual first slide out of the way. 这对我来说只是一个纯铬的错误,其中用于从最后一张幻灯片回到第一张幻灯片的无缝滚动的“克隆幻灯片”将首先显示实际的第一张幻灯片。 Hiding the clone slide is a quick fix but breaks the infinite scrolling effect. 隐藏克隆幻灯片是一个快速修复,但打破了无限滚动效果。

This below solution fixed it for me strictly with CSS, no gnarly 3D transform CSS, Jquery, or anything... plays OK with bootstrap now: 以下解决方案严格使用CSS修复它,没有粗糙的3D转换CSS,Jquery或任何其他...现在可以使用bootstrap正常运行:

/* BUG FIX FOR CLONE SLIDE FIRST */

.bx-wrapper img {
    max-width: 100%;
    display: inline-block;
}

.bx-viewport li { 
    min-height: 1px; 
    min-width: 1px; 
}

I think if you're using jquery to show the clone using onSlideBefore you've gone too far, there is probably a CSS fix depending on your specific situation. 我想如果你使用jquery使用onSlide来显示克隆,那么在你走得太远之前,可能会有一个CSS修复,具体取决于你的具体情况。 Sometimes it stems from an image size and/or display style issue with BOOTSTRAP, so if you're using BS, there's a CSS fix for sure. 有时它源于BOOTSTRAP的图像大小和/或显示样式问题,因此如果您使用的是BS,那么肯定会有CSS修复。 In general, if all of your slides are the same size try setting the height and width, max height and width, and min height and width for the images and it may fix it. 通常,如果所有幻灯片的大小相同,请尝试设置图像的高度和宽度,最大高度和宽度以及最小高度和宽度,它可以修复它。

This isn't necessary, but if that doesn't work, in the bxSlider init options try useCSS: false, ex: 这不是必需的,但是如果这不起作用,在bxSlider init选项中尝试使用CSS:false,ex:

$(window).load(function(){
        $('.bxslider').bxSlider({
            pagerCustom: '#bx-pager',
            randomStart: false,
            controls: true,
            auto: true
            useCSS:false
        });    
    });

You just need to stop the loop : 你只需要停止循环:

infiniteLoop:false

...and there is no more .bx-clone ...而且没有.bx-clone

http://bxslider.com/options http://bxslider.com/options

As mentioned by OG Sean it´sa Chrome bug. 正如OG Sean所提到的那样是一个Chrome bug。

I hade the same problem and the only thing needed when i tried was this css code: 我讨厌同样的问题,我尝试时唯一需要的是这个css代码:

.bx-viewport li { min-height: 1px; min-width: 1px; }

好吧我不知道为什么,但当我删除这行“minSlides:2”时,它开始以正确的方式工作。

<li>
    <img src="_images/xxx.jpg" alt="xxx" width="X" height="X"/>
</li>

Setting an explicit height and width tag on the images in the slider fixed this issue for me with sliders containing 2-5 images. 在滑块上的图像上设置显式的高度和宽度标签为我修复了这个问题,滑块包含2-5个图像。

使用bxslider是我生命中最大的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM