css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
<h2>Load a carousel for your image based tumblr blog</h2>

<div class="carousel-container">
  <div class="preloader"></div>
  <button class="fa fa-chevron-left arrow-left" disabled="true"></button>
  <div class="outer">
    <div class="inner">
    </div>
  </div>
  <button class="fa fa-chevron-right arrow-right"></button>
<div>

<div class="input-container">
  <p>Enter your tumblr blog name</p>
  <form id="tumblr-form",class="pure-form">
    <input id="blog-name",type="text", placeholder="enter your tumblr blog name", value="satoriwild"/>
    <input id="refresh-name", type="button", value="Load", class="pure-button pure-button-primary" />
     
  </form>
</div>
            
          
!
            
              body
  font-family lato
  h2
    text-align center

  .carousel-container
    position relative
    .preloader
      top 50px
      position relative
      margin 0 auto
      text-align center
      width 64px
      height 64px
      background url(http://preloaders.net/preloaders/712/Floating%20rays.gif)
    .outer
      width 740px
      min-height 148px
      overflow hidden
      margin 0 auto
      
      .inner
        width 500%
        position relative
        .set
          float left
      
  .input-container
     text-align center
     #blog-name
       width 250px
       height 30px
       padding 0 10px
  .img-wrapper
    width 128px
    height 128px
    overflow hidden
    margin 10px
    display inline-block
    vertical-align top
    border-radius 4px

  .img-wrapper img
    max-width 100%
    width auto
    

  .img-wrapper img.landscape
    max-width none
    max-height 100%
    

.arrow-left, .arrow-right
  cursor pointer
  position absolute
  top 25%
  background transparent
  border none
  
.arrow-left
  left 16%
  
.arrow-right
   left 82%

            
          
!
            
              Carousel = (function() {
  function Carousel() {}

  Carousel.prototype.init = function() {
    var i, numPerSlide, numTiles, tiles, width;
    this.arrowRight = $('.fa-chevron-right');
    this.arrowLeft = $('.fa-chevron-left');
    numPerSlide = 5;
    tiles = $('.img-wrapper');
    numTiles = $('.img-wrapper').length;
    this.numSets = Math.ceil(numTiles / numPerSlide);
    this.activeIndex = 0;
    this.frame = $('.inner');
    i = 0;
    while (i < tiles.length) {
      $(tiles).slice(i, i + numPerSlide).wrapAll("<div class='set'></div>");
      i += numPerSlide;
    }
    width = $(".inner .set").eq(0).width();
    $(this.arrowLeft).on("click", (function(_this) {
      return function(event) {
        return _this.handleMoveLeft(width);
      };
    })(this));
    return $(this.arrowRight).on("click", (function(_this) {
      return function(event) {
        console.log("move right click");
        return _this.handleMoveRight(width);
      };
    })(this));
  };

  Carousel.prototype.highlightDot = function(index) {};
  /*  $(@dots).removeClass("active")
    $(@dots).eq(index).addClass("active")
   */

  Carousel.prototype.updateControls = function() {
    $(this.arrowRight).prop("disabled", false);
    $(this.arrowRight).removeClass("inactive");
    $(this.arrowLeft).prop("disabled", false);
    $(this.arrowLeft).removeClass("inactive");
    if (this.activeIndex === (this.numSets - 1)) {
      $(this.arrowRight).addClass("inactive");
      $(this.arrowRight).prop("disabled", true);
    }
    if (this.activeIndex === 0) {
      $(this.arrowLeft).addClass("inactive");
      return $(this.arrowLeft).prop("disabled", true);
    }
  };

  Carousel.prototype.moveContent = function(index, width) {
    var moveWidth;
    console.log("move content", width);
    moveWidth = -Math.abs(index * width);
    return TweenMax.to($(this.frame), 0.5, {
      right: 0,
      left: moveWidth,
      ease: Quad.easeOut
    });
  };

  Carousel.prototype.showPage = function(index, width) {
    this.moveContent(index, width);
    this.highlightDot(index);
    this.activeIndex = index;
    return this.updateControls();
  };

  Carousel.prototype.handleMoveLeft = function(width) {
    var index;
    index = this.activeIndex - 1;
    this.showPage(index, width);
    this.highlightDot(index);
    this.activeIndex = index;
    return this.updateControls();
  };

  Carousel.prototype.handleMoveRight = function(width) {
    var index;
    console.log("handle move right");
    index = this.activeIndex + 1;
    this.showPage(index, width);
    this.highlightDot(index);
    this.activeIndex = index;
    return this.updateControls();
  };

  return Carousel;

})();
// Populate caorusel
var tumblr = tumblr_api_read.posts;
var carousel, img, wrappedImg;
var i = 0
while (i < tumblr.length) {
  img = $('<img>');
  if (tumblr[i]['photo-url-250'] != null) {
    $(img).attr('src', tumblr[i]['photo-url-250']);
    $(img).wrap('<a class="img-wrapper"></a>');
    wrappedImg = $(img).parent();
    $(wrappedImg).attr({
      'href': tumblr[i]['photo-url-500'],
      'data-featherlight': "image"
    });
    $('.inner').append(wrappedImg);
    $('.inner').imagesLoaded(function(instance) {
      
      _.each(instance.images, function(image) {
        img = image.img;
				$('.preloader').hide()
        if (img.width > img.height) {
          img.className = 'landscape';
        } 
      });
    });
  }
  i++;
}

carousel = new Carousel;
carousel.init();

// ---
// generated by coffee-script 1.9.0

$('#refresh-name').click((function(_this) {
  return function() {
   	$('.preloader').show()
	  console.log('inner click');
    var endpointFirstPart, endpointSecondPart, tumblrName, url;
    console.log('form submit');
    $('.inner').empty();
    tumblrName = $('#blog-name').val().toLowerCase();
    endpointFirstPart = 'https://';
    endpointSecondPart = '.tumblr.com/api/read/json';
    url = endpointFirstPart + tumblrName + endpointSecondPart;
    $.ajax({
      type: 'GET',
      url: url,
      async: false,
      jsonpCallback: 'jsonCallback',
      contentType: 'application/json',
      dataType: 'jsonp',
      success: function(json) {
        var carousel, i, img, wrappedImg;
        console.dir(json);
        tumblr = json.posts;
        i = 0;
        while (i < tumblr.length) {
          img = $('<img>');
          if (tumblr[i]['photo-url-250'] != null) {
            $(img).attr('src', tumblr[i]['photo-url-250']);
            $(img).wrap('<a class="img-wrapper"></a>');
            wrappedImg = $(img).parent();
            $(wrappedImg).attr({
              'href': tumblr[i]['photo-url-500'],
              'data-featherlight': "image"
            });
            $('.inner').append(wrappedImg);
            $('.inner').imagesLoaded(function(instance) {
              $('.preloader').hide()
              _.each(instance.images, function(image) {
                img = image.img;
                console.log("img", img);
                if (img.width > img.height) {
                  img.className = 'landscape';
                } 
              });
            });
          }
          i++;
        }
        carousel = new Carousel;
        return carousel.init();
      },
      error: function(e) {
        console.log(e.message);
      }
    });
  };
})(this));

$('.img-wrapper').featherlight();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console