How can we skip display:none items in owl carousel?

KA9

Can anyone please tell how can we skip display:none items in owl carousel?

My html is like this :-

<div id="owl-demo">
      <div class="item" id="image1"><img src="images/1.jpg" alt="Owl Image"></div>
      <div class="item" id="image2"><img src="images/2.jpg" alt="Owl Image"></div>
      <div class="item" id="image3"><img src="images/3.jpg" alt="Owl Image"></div>
      <div class="item" id="image4" style="display:none;"><img src="images/4.jpg" alt="Owl Image"></div>
      <div class="item" id="image5"><img src="images/5.jpg" alt="Owl Image"></div>
      <div class="item" id="image6"><img src="images/6.jpg" alt="Owl Image"></div>
      <div class="item" id="image7"><img src="images/7.jpg" alt="Owl Image"></div>
      <div class="item" id="image8"><img src="images/8.jpg" alt="Owl Image"></div>
    </div>

Here is my jquery :-

<script>
    jQuery(document).ready(function() {

      jQuery("#owl-demo").owlCarousel({

          autoPlay: 3000, //Set AutoPlay to 3 seconds
          navigation : true,
          items : 4,
          itemsDesktop : [1199,3],
          itemsDesktopSmall : [979,3]
      });

      //jQuery("#owl-demo").data('owlCarousel').visibleItems;
    });
</script>

Now the issue is I do not want to display the "display:none" items. Now the display none items are not coming but at the end there comes a space, that should not come.

Any one can help please?

Thanks.

KA9

Finally I got the solution. Well but not the owl-carousel way. It's not possible to skip the display:none items in owl-carousel. Here is the custom solution.

I took the new div in which I got the collection of lis but I gave them hid class so all will be hidden(hid = css class with display:none) Then look at the javascript I put in code.

Html is like this :-

<style type="text/css">
  .hid{display: none;}
</style>

<button onclick="reinitcarousel(1)">Tab 1</button><button onclick="reinitcarousel(2)">Tab 2</button>
    <div id="owl-demo">
      <div class="item im1" id="image1"><img src="images/1.jpg" alt="Owl Image"></div>
      <div class="item im1" id="image2"><img src="images/2.jpg" alt="Owl Image"></div>
      <div class="item im1" id="image3"><img src="images/3.jpg" alt="Owl Image"></div>
      <div class="item im1" id="image4"><img src="images/4.jpg" alt="Owl Image"></div>
      <div class="item hid im2" id="image5"><img src="images/5.jpg" alt="Owl Image"></div>
      <div class="item hid im2" id="image6"><img src="images/6.jpg" alt="Owl Image"></div>
      <div class="item im1" id="image7"><img src="images/7.jpg" alt="Owl Image"></div>
      <div class="item im1" id="image8"><img src="images/8.jpg" alt="Owl Image"></div>
    </div>

    <div id="anotherdiv" style="display:none;">
      <div class="item hid im1" id="image1"><img src="images/1.jpg" alt="Owl Image"></div>
      <div class="item hid im1" id="image2"><img src="images/2.jpg" alt="Owl Image"></div>
      <div class="item hid im1" id="image3"><img src="images/3.jpg" alt="Owl Image"></div>
      <div class="item hid im1" id="image4"><img src="images/4.jpg" alt="Owl Image"></div>
      <div class="item hid im2" id="image5"><img src="images/5.jpg" alt="Owl Image"></div>
      <div class="item hid im2" id="image6"><img src="images/6.jpg" alt="Owl Image"></div>
      <div class="item hid im1" id="image7"><img src="images/7.jpg" alt="Owl Image"></div>
      <div class="item hid im1" id="image8"><img src="images/8.jpg" alt="Owl Image"></div>
    </div>

Script is like this :-

<script>
jQuery('#owl-demo .hid').remove(); //At the time of page load, first remove all lis having hid class

//Then load the carousel
jQuery(document).ready(function() {
  jQuery("#owl-demo").owlCarousel({
      autoPlay: 3000, //Set AutoPlay to 3 seconds
      navigation : true,
      items : 4,
      itemsDesktop : [1199,3],
      itemsDesktopSmall : [979,3],
      loop:true,
      rewindNav: false
  });
});
</script>

<script type="text/javascript">
  function reinitcarousel(v) //When you click on any tab
  {
    jQuery('#owl-demo').html(jQuery('#anotherdiv').html()); //Remove all lis in owl-demo div & place lis of anotherdiv div where all lis having class hid
    jQuery('#owl-demo .im'+v).removeClass('hid'); //Then again remove class hid having class .im(v) where v is a number
    jQuery('#owl-demo .hid').remove(); //Then remove all lis having class hid so our carousel will have only visible lis only

    jQuery("#owl-demo").data('owlCarousel').destroy(); //We need to destroy carousel first & then reinitialize like below
    jQuery("#owl-demo").owlCarousel({
        autoPlay: 3000, //Set AutoPlay to 3 seconds
        navigation : true,
        items : 4,
        itemsDesktop : [1199,3],
        itemsDesktopSmall : [979,3],
        loop:true
    });
  }
</script>

Done :)

Thanks.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Owl Carousel 2 sets itself to display none

From Dev

How to display the owl Carousel navigation in the center?

From Dev

Cloned items in owl carousel

From Dev

Update owl carousel items

From Dev

How can I add class to the first and last item among the visible items of Owl Carousel 2?

From Dev

How can i animate display: none / block property on flex items?

From Dev

How do I add classes to items in Owl Carousel 2?

From Dev

Slide 2 items in OWL Carousel

From Dev

How can I use Owl Carousel 2 in Angular2?

From Dev

Owl carousel items content not able to copy

From Dev

Owl carousel issue on JS counting the items

From Dev

How can I center items in Slick Carousel?

From Dev

How to center the images in the Owl Carousel

From Dev

How to Slide all visible items in Owl Carousel instead of one using prev/next button

From Dev

How to Slide all visible items in Owl Carousel instead of one using prev/next button

From Dev

Owl Carousel - Slide orders, skip straight to selected slide

From Dev

How to get Owl Carousel Owl-Page (dots) Responsive

From Dev

How can I stop Owl carousel from rewinding? I just want a seamless loop

From Dev

Next and Prev button will slides 2 items on OWL Carousel

From Dev

Owl carousel all items visible when page is loading

From Dev

Owl Carousel 2: filtering items, but keep the sort order using Javascript

From Dev

Show part of next and previous items with Owl Carousel 2.0

From Dev

Owl carousel on meteor always set 5 items even on a smaller device

From Dev

Owl carousel items order starts with the item in the middle of the list

From Dev

owl carousel 2 not work with loop and 1 items (Bug Fixed Now)

From Dev

Next and Prev button will slides 2 items on OWL Carousel

From Dev

Owl carousel items order starts with the item in the middle of the list

From Dev

How to show div that is display:none if shopping cart is empty of items?

From Dev

How can we skip a record while looping through an array in ReactJS

Related Related

  1. 1

    Owl Carousel 2 sets itself to display none

  2. 2

    How to display the owl Carousel navigation in the center?

  3. 3

    Cloned items in owl carousel

  4. 4

    Update owl carousel items

  5. 5

    How can I add class to the first and last item among the visible items of Owl Carousel 2?

  6. 6

    How can i animate display: none / block property on flex items?

  7. 7

    How do I add classes to items in Owl Carousel 2?

  8. 8

    Slide 2 items in OWL Carousel

  9. 9

    How can I use Owl Carousel 2 in Angular2?

  10. 10

    Owl carousel items content not able to copy

  11. 11

    Owl carousel issue on JS counting the items

  12. 12

    How can I center items in Slick Carousel?

  13. 13

    How to center the images in the Owl Carousel

  14. 14

    How to Slide all visible items in Owl Carousel instead of one using prev/next button

  15. 15

    How to Slide all visible items in Owl Carousel instead of one using prev/next button

  16. 16

    Owl Carousel - Slide orders, skip straight to selected slide

  17. 17

    How to get Owl Carousel Owl-Page (dots) Responsive

  18. 18

    How can I stop Owl carousel from rewinding? I just want a seamless loop

  19. 19

    Next and Prev button will slides 2 items on OWL Carousel

  20. 20

    Owl carousel all items visible when page is loading

  21. 21

    Owl Carousel 2: filtering items, but keep the sort order using Javascript

  22. 22

    Show part of next and previous items with Owl Carousel 2.0

  23. 23

    Owl carousel on meteor always set 5 items even on a smaller device

  24. 24

    Owl carousel items order starts with the item in the middle of the list

  25. 25

    owl carousel 2 not work with loop and 1 items (Bug Fixed Now)

  26. 26

    Next and Prev button will slides 2 items on OWL Carousel

  27. 27

    Owl carousel items order starts with the item in the middle of the list

  28. 28

    How to show div that is display:none if shopping cart is empty of items?

  29. 29

    How can we skip a record while looping through an array in ReactJS

HotTag

Archive