16

Bootstrap のカルーセルを使用して、リンクをクリックしてカルーセル内の特定のスライドにジャンプできるようにしたいと考えています。それ、どうやったら出来るの?どのjqueryを追加する必要がありますか?

これが私のhtmlです(機能しませんが、私が何をしたいのかがわかります):

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

<div id="myCarousel" class="carousel slide">
 <div class="carousel-inner">
  <div id="panel" class="item">
...
  </div>
 </div>
</div>
4

2 に答える 2

26

リンクがパネルと同じ順序になっている場合は、次のようにすることができます。

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

リンクが1つしかない場合は、ハードコーディングします。

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

ドキュメントから:

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.
于 2013-02-01T11:09:31.097 に答える