Search code examples
cssmaterialize

two carousel in same page, materializecss


This is a materializecss carousel.
The first carousel works perfectly fine. If i want to create the second carousel on the same page it creates issue.

I have tried changing the class carousel to carousel1 and called $('.carousel1.carousel-slider').carousel({full_width: true});

The second carousel is misaligned and carousel does not get initialised.

Need guidance.

<div class="carousel carousel-slider center" data-indicators="true">
    <div class="carousel-fixed-item center">
      <a class="btn waves-effect white grey-text darken-text-2">button</a>
    </div>
    <div class="carousel-item red white-text" href="#one!">
      <h2>First Panel</h2>
      <p class="white-text">This is your first panel</p>
    </div>
    <div class="carousel-item amber white-text" href="#two!">
      <h2>Second Panel</h2>
      <p class="white-text">This is your second panel</p>
    </div>
    <div class="carousel-item green white-text" href="#three!">
      <h2>Third Panel</h2>
      <p class="white-text">This is your third panel</p>
    </div>
    <div class="carousel-item blue white-text" href="#four!">
      <h2>Fourth Panel</h2>
      <p class="white-text">This is your fourth panel</p>
    </div>
  </div>

Solution

  • Instead of initializing your carousel with classes give each carousel an id and then initiate them with the id's instead of the classes so each one is unique.