Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump to a specific item in Bootstrap's Carousel? [duplicate]

Using Bootstrap's Carousel, I want to be able to click on a link and jump to a specific slide in the carousel. How do I do that? What jquery do I have to add?

Here's my html (it doesn't work but gives you a sense of what I want to do):

<a href="#panel">Panel</a>

<div id="myCarousel" class="carousel slide">
 <div class="carousel-inner">
  <div id="panel" class="item">
...
  </div>
 </div>
</div>
like image 209
Elijah Yang Avatar asked Feb 01 '13 11:02

Elijah Yang


People also ask

How do you control carousel speed?

If you are using bootstrap carousel, then you need to provide the data-interval attribute on your main carousel div to change the speed of carousel. Ex. Here the value 3000 is in msec. If you are not using bootstrap carousel, then specify more details what exactly you have done so far.

How do you change the interval of a carousel?

You can simply use the data-interval attribute of the carousel class. It's default value is set to data-interval="3000" i.e 3seconds. All you need to do is set it to your desired requirements.

How can I use two bootstrap carousel in one page?

To insert multiple jQuery carousels to the same webpage, you need to create each carousel with a unique ID. In Amazing Carousel, Publish dialog, select the option Publish to Folder, then click Browse to select a folder to save the generated files. You need to set up a unique Carousel ID for each carousel.


1 Answers

if your links are in the same order of the panels you can do something like:

$('.link').on('click', function() {
    $('#carousel').carousel($(this).index());
});

if you just have a single link just hardcode it:

var i = 2; //index of the panel    
$('#link').on('click', function() {
    $('#carousel').carousel(i);
});

from the docs:

Methods:

carousel(options)

Initializes the carousel with an optional options object and starts cycling through items.

$('.carousel').carousel({
  interval: 2000
})
.carousel('cycle')

Cycles through the carousel items from left to right.

.carousel('pause')

Stops the carousel from cycling through items.

.carousel(number)

Cycles the carousel to a particular frame (0 based, similar to an array).

.carousel('prev')

Cycles to the previous item.

.carousel('next')

Cycles to the next item.
like image 85
David Fregoli Avatar answered Sep 21 '22 08:09

David Fregoli