Reset Twiiter bootstrap coil on page scrolls

Does anyone know if there is a way to reset the twitter bootstrap carousel when it is no longer visible?

I have this at the top of a page with three slides, is there a way to move it back to the first one when users scroll to the rest of the page?

Thank you in advance

0


source to share


2 answers


You should probably optimize the code a bit, but this should start:



var getPageScroll = function(document_el, window_el) {
      var xScroll = 0, yScroll = 0;
      if (window_el.pageYOffset !== undefined) {
        yScroll = window_el.pageYOffset;
        xScroll = window_el.pageXOffset;
      } else if (document_el.documentElement !== undefined && document_el.documentElement.scrollTop) {
        yScroll = document_el.documentElement.scrollTop;
        xScroll = document_el.documentElement.scrollLeft;
      } else if (document_el.body !== undefined) {// all other Explorers
        yScroll = document_el.body.scrollTop;
        xScroll = document_el.body.scrollLeft;
      }
      return [xScroll,yScroll];
    };

    $(window).scroll(function(e) {
        var top = $('#carousel-example-generic').offset().top;
        if(top < getPageScroll(document,window)[1]) $('#carousel-example-generic').carousel(0);
    });

      

0


source


In the carousel documentation , you have the following:

.carousel(number)

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

      



So, if you want to go back to the first item, all you have to do is use this :) $('#myCarousel').carousel(0

;

+1


source







All Articles