cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="row">
  <div class="col-md-12">
    <div data-ride="carousel" class="carousel slide row" id="carousel-example">
      <div class="carousel-inner" role="listbox">
        <div class="item active">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">											
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->          

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->

        <div class="item">
          <div class="element col-md-3 col-sm-6 col-xs-12">
            <img width="220" height="290" src="http://lorempixel.com/220/290/">													
          </div><!-- .element -->
        </div><!-- .item -->                    
      </div><!-- .carousel-inner -->

      <!-- Controls -->
      <a class="left carousel-control" href="#carousel-example" role="button" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#carousel-example" role="button" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div><!-- #carousel-example -->
  </div>
</div>
            
          
!
            
              jQuery(document).ready(function($) {
  var $window = $(window);

  /**
   * responsiveCarousel - check the window size and generate the carousel with specified number of elements
   */
  function responsiveCarousel() {
    var windowsize = $window.width();

    if (windowsize < 768) {
      generateCarousel(getCarouselElements(), 1);
    } else if (windowsize >= 768 && windowsize < 992) {
      generateCarousel(getCarouselElements(), 2);
    } else if (windowsize >= 992) {
      generateCarousel(getCarouselElements(), 4);
    }
  }

  /**
   * getCarouselElemets 	Loop trough the carousel content and hold the elements into an array
   * @return array 		Array of jQuery objects
   */
  function getCarouselElements() {
    var $elements = [];

    $('#carousel-example').find('.item').each(function() {
      $(this).find('.element').each(function() {
        $elements.push($(this));
      });
    });

    return $elements;
  }

  /**
   * generateCarousel 				Generate carousel according to the number of elements to be displayed per item
   * @param  array $elements          Elements to be inserted in carousel
   * @param  int number_of_elements 	Number of elements to be displayed per item
   */
  function generateCarousel($elements, number_of_elements) {
    $container = $('#carousel-example').find('.carousel-inner');
    $container.empty();

    for (var i = 0; i < $elements.length; i++) {
      // Append the current section <div> if is multiple of number of elements
      if ( i % number_of_elements == 0 ) {
        var $current_section = $('<div class="item"></div>').appendTo($container);
      }

      // If is the first element, add class active
      if (i == 0) {
        $current_section.addClass('active');
      }

      // Append element to the current section
      $current_section.append($elements[i]);
    }
  }

  // Execute on load
  responsiveCarousel();

  // Bind event listener
  $(window).resize(responsiveCarousel);
});
            
          
!
999px
Loading ..................

Console