Do not allow moving when there is only one bxSlider.js image

Asked

Viewed 19 times

-1

I am using bxslider and rodo perfectly the following code:

  <script>
      $(document).ready(function(){
         $('.slider').bxSlider({
              auto: true
        });
     });
  </script>

Which results in card drive..

I have this div that inside it contains an image. the insertion of the image is dynamic according to a foreach...

<div class="slider">
     <img id="ImgBanner" src="..."> 
</div>

I need that when you only have one image, it does not allow dragging and becomes "static" and when there is more than one image, normally work the drag option.

I tried using the following code and resulted in nothing:

$(document).ready(function(){
   $('.slider').bxSlider({
          auto: ($("#ImgBanner").length > 1) ? true: false,
          pager: ($("#ImgBanner").length > 1) ? true: false,
         controls: false
   });
 });
  • 1

    the stretch $("#ImgBanner").length returns the quantity of the correct form?

  • Missing the div that encompassed, thank you for your reply.

1 answer

0

The solution was this, where I check the amount of images and create a ternary operator according to the result, enabling or not the touch:

   $(document).ready(function(){
            $('.slider').bxSlider({
                auto: true,
                touchEnabled:($('.slider #ImgBanner').length > 1) ? true : false,
            });
   });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.