Reputation: 35
I have a twitter Bootstrap Carousel and I am trying to link to its seperate slide from external pages. I need to do it using a url.
etc.
http://www.example.com/carousel.html#item3:active
to set the third slide as active
Is there a way I could do it?
Upvotes: 3
Views: 356
Reputation: 4141
That's perfectly possible. You can get the part after the #
in the current URL via document.location.hash
, and you can link to a specific slide with $('.some-carousel').carousel(slideNr)
. Put together, your code might look like the following:
$(function () {
var slide = document.location.hash.match(/^slide-(\d+)$/);
if (slide) {
$('.some-carousel').carousel(parseInt(slide[1], 10));
}
});
Upvotes: 1