skip to Main Content

Here’s the problem, I want two carousel with two different function in one page which mean the first carousel will be auto slide and the second carousel will be manually click but i got this problem:

  1. When the first carousel slide, the second carousel will be gone.

  2. When the second carousel clicked, the first carousel not responding.

So, here’s my code

$(document).ready(function() {
  $('#carousel-1').carousel({
    interval: 5000
  });
});

$(document).ready(function() {
  $('#carousel-2').carousel({
    interval: false
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<div id="carousel-1" class="carousel slide">
  <div class="carousel-inner">
    <div class="item active">
      <img src="http://placehold.it/350x150" alt="" />
    </div>
    <div class="item">
      <img src="http://placehold.it/350x150" alt="" />
    </div>
    <div class="item">
      <img src="http://placehold.it/350x150" alt="" />
    </div>
  </div>

  <div class="container">
    <div id="carousel-2" class="carousel slide">
      <div class="carousel-inner">
        <div class="item active">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
        <div class="item">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
        <div class="item">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
      </div>
      <a class="carousel-control left" href="#carousel-2" data-slide="prev">&lsaquo;</a>
      <a class="carousel-control right" href="#carousel-2" data-slide="next">&rsaquo;</a>
    </div>
  </div>

Here’s also my fiddle https://jsfiddle.net/za9un2wc/

I’m using Twitter Bootstrap for my work here. Any suggestion/solution can you guys give to me? Thanks

2

Answers


  1. just add href=”#carousel-2″ in navigation of second one

    Login or Signup to reply.
  2. You should add </div> before second carousel.
    I’m not sure it is enough for you, but looks good in my opinion.

    <div id="carousel-1" class="carousel slide">
      <div class="carousel-inner">
        <div class="item active">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
        <div class="item">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
        <div class="item">
          <img src="http://placehold.it/350x150" alt="" />
        </div>
      </div>
    </div><!-- Added div -->
    <div class="container">
      <div id="carousel-2" class="carousel slide">
        <div class="carousel-inner">
          <div class="item active">
            <img src="http://placehold.it/350x150" alt="" />
          </div>
          <div class="item">
            <img src="http://placehold.it/350x150" alt="" />
          </div>
          <div class="item">
            <img src="http://placehold.it/350x150" alt="" />
          </div>
        </div>
        <a class="carousel-control left" href="#carousel-2" data-slide="prev">&lsaquo;</a>
        <a class="carousel-control right" href="#carousel-2" data-slide="next">&rsaquo;</a>
      </div>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search