0

I need to provide direct links slides in one carousel. I have tried to implement this solution but with no success. I need some URL like: wwww.domain.com/index.html#slide20" to open directly the item slide.

I have a carousel with a 59 items, and like to be able to open in any one of them... from a external web page... There is any javascript configuration possible?

Should use any of this id tags?

<div class="item" id="51" data-id="51" data-slide="51">
   ...
</div>
Community
  • 1
  • 1
Pangolim
  • 1
  • 1

1 Answers1

0

#slide20 would automatically scroll to the element that has the ID slide20 (if existing). Give your carousel an ID or class, and use the following code to slide to a certain number. For this to work, you must make sure that slide 20 is the 20th slide, depending on the implementation.

If you have 59 elements in your carousel, make sure that #slide20 opens the 20th slide.

In this example, your carousel has an ID of myCarousel.

$(document).ready(function() {
    $("#myCarousel").carousel(window.location.hash.substr(6) - 1);
});

This code is untested, but what it does is retrieving the value behind the #slide. window.location.hash returns #slide20, but you are only interested in the 20. You want the 7th (and more) character, and you start with an index of 0, so that'd leave you with substr(6). Substract 1 from that number, as slide1 should be the first slide, but Bootstrap counts from index 0 too.

I have not tested the code, but it should work, seeing Bootstrap's code.

Ruben Rutten
  • 1,659
  • 2
  • 15
  • 30