Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. $('.carousel').carousel();
  2. var caption = $('div.item:nth-child(1) .carousel-caption');
  3. $('#right').html(caption.html());
  4. caption.css('display','none');
  5. $(".carousel").on('slide.bs.carousel', function(evt) {
  6.  
  7. var caption = $('div.item:nth-child(' + ($(evt.relatedTarget).index()+1) + ') .carousel-caption');
  8. $('#right').html(caption.html());
  9. caption.css('display','none');
  10. });
  11.  
  12. <p id="right"></p>
  13.  
  14. $(document).ready(function() {
  15.  
  16. var url = document.location.toString();
  17. var totalItems = $('.item').length;
  18.  
  19. //Initiate carousel
  20. $('.carousel').carousel({
  21. interval: false
  22. })
  23.  
  24. $('.carousel').on('slid.bs.carousel', function () {
  25.  
  26. var currentIndex = $('div.active').index() + 1;
  27.  
  28. //Update pager-text
  29. $('.pager-text').text(''+currentIndex+'/'+totalItems+'');
  30.  
  31. // Update location based on slide (index is 0-based)
  32. window.location.hash = "#"+ parseInt($('.carousel .carousel-inner .item.active').index()+1);
  33. });
  34.  
  35.  
  36. if (url.match('#')) {
  37. // Clear active item
  38. $('.carousel .carousel-inner .item.active').removeClass('active');
  39.  
  40. // Activate item number #hash
  41. $('.carousel-inner div:nth-child(' + url.split('#')[1] + ')').addClass('active');
  42.  
  43. //Update pager-text
  44. $('.pager-text').text(''+url.split('#')[1]+'/'+totalItems+'');
  45.  
  46. }
  47.  
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement