Search code examples
jquerybxslider

Bx slider - li width adjust based on content in mulitple number of slides


I am implementing the bx slider. I using the text content in slider. I need the li content width adjust based on content. because some of li content is large content and some of them small.Have any default option having? I tried the following code.

Html Code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://bxslider.com/lib/jquery.bxslider.min.js"></script>

<ul class="bxslider">
<li>1 Lorem ipsum dolor sit amet</li>
<li>2  sit amet </li>
<li>3 Lorem ipsum t</li>
<li>4 Lorem ipsum dolor sit amet dolor sit amet </li>
<li>5 Lorem </li>
<li>6 Lorem ipsum dolor sit amet</li>
<li>7 Lorem</li>
<li>8 Lorem ipsum dolor sit amet</li>
<li>9 Lor</li>
<li>10 Lorem ipsum dolor sit amet</li>

<div class="outside">
<h3>This div is outside of the slider</h3>
<span id="slider-prev"></span> | <span id="slider-next"></span>
</div>

Js code:

$('.bxslider').bxSlider({
  nextSelector: '#slider-next',
  prevSelector: '#slider-prev',
  nextText: 'Onward →',
  prevText: '← Go back',
  minSlides: 3,
  maxSlides: 5,
  slideWidth: 360,
  slideMargin: 0,
  adaptiveHeight: true,
  infiniteLoop: false,
  hideControlOnEnd: true
});

JsFiddle Link : http://jsfiddle.net/nwvW9/85/


Solution

  • You can't use default options of BXSlider to achieve this. However with some hacks you can.

    Remove the fixed slide width line.

      slideWidth: 360,
    

    Add the CSS. (Use important carefully)

    li{
        width: initial !important;
        margin: 0px 20px;
    }
    

    Fiddle: http://jsfiddle.net/36opbff9/