Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="block">
  <div class="item-list animation-container">
    <div class="item animation-slide s1">
      <a href="#">
        <div class="item-graphic bg-green"></div>
        <p class="item-title">1</p>
      </a>
      <div class="item-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fugiat minus ipsa repellendus, ea, aliquid ullam quas earum dicta unde ut laborum odit quisquam, provident cumque, maiores voluptate blanditiis iusto?
      </div>
    </div>
    <div class="item animation-slide s2">
      <a href="#">
        <div class="item-graphic bg-blue"></div>
        <p class="item-title">2</p>
      </a>
      <div class="item-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fugiat minus ipsa repellendus, ea, aliquid ullam quas earum dicta unde ut laborum odit quisquam, provident cumque, maiores voluptate blanditiis iusto?
      </div>
    </div>
    <div class="item animation-slide s3">
      <a href="#">
        <div class="item-graphic bg-yellow"></div>
        <p class="item-title">3</p>
      </a>
      <div class="item-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fugiat minus ipsa repellendus, ea, aliquid ullam quas earum dicta unde ut laborum odit quisquam, provident cumque, maiores voluptate blanditiis iusto?
      </div>
    </div>
    <div class="item animation-slide s4">
      <a href="#">
        <div class="item-graphic bg-orange"></div>
        <p class="item-title"> 4</p>
      </a>
      <div class="item-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fugiat minus ipsa repellendus, ea, aliquid ullam quas earum dicta unde ut laborum odit quisquam, provident cumque, maiores voluptate blanditiis iusto?
      </div>
    </div>
    <div class="item animation-slide s5">
      <a href="#">
        <div class="item-graphic bg-red"></div>
        <p class="item-title">5</p>
      </a>
      <div class="item-content">
        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Impedit fugiat minus ipsa repellendus, ea, aliquid ullam quas earum dicta unde ut laborum odit quisquam, provident cumque, maiores voluptate blanditiis iusto?
      </div>
    </div>
  </div>
</section>
              
            
!

CSS

              
                .block {
  text-align: center;
  padding: 55px 0;
  position: relative;
}
.item-list {
  overflow: hidden;
}
.animation-container {
  overflow: hidden;
  position: relative;
  white-space: nowrap;
}
.animation-viewport {
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 100%;
}
.item {
  display: inline-block;
  text-align: left;
  margin: 0 60px;
  font-size: 24px;
  &.is-active {
    width: calc( 100% - 412px );
  }
  .item-title {
    margin-left: 30px;
  }
  .item-graphic {
    height: 300px;
    width: 100px;
    border-radius: 30px;
    &.bg-red { background-color: red; }
    &.bg-blue { background-color: blue; }
    &.bg-green { background-color: green; }
    &.bg-yellow { background-color: yellow; }
    &.bg-orange { background-color: orange; }
    &.is-active {
      height: 600px;
      width: 170px;
    }
    img {
      height: 100%;
      width: auto;
    }
  }
}
.item-content {
  position: absolute;
  bottom: 0;
  left: 200px;
  transform: translateY(100%);
}
              
            
!

JS

              
                var $container = $('.animation-container');
var $selector = $('.animation-slide');
var $items = $container.find($selector);
var movement_tl = new TimelineMax({ onUpdate: setPosition });
var activeIndex = 0;
var centerOffset = 0;
var viewport;
var is_zoomed = 0;
var zoomDuration = 0.8;



$('.item a').on('click', function(e) {
  e.preventDefault();

  var $parent = $(this).closest('.item');
  $selector.not($parent).removeClass('is-active');
  $selector.not($parent).attr('data-is-selected', false);
  
  if( $parent.attr('data-is-selected') == "true" ) {
    $parent.attr('data-is-selected', false);
    viewport = '';
    is_zoomed = 0;
    setItemPosition();
    movementAnimation();
    labelAnimation();
  } else {
    $parent.attr('data-is-selected', true);
    activeIndex = $parent.index();
    viewport = 'showroom';
    movementAnimation('play');
    labelAnimation('play');
    is_zoomed++;
  }
});

init();
$(window).on('resize', function(e){
  setPosition();
});

function movementAnimation( type ) {
    TweenMax.killTweensOf(movement_tl);
    if( type == 'play') {
      if( is_zoomed == 0 ) {
        movement_tl.to( $('.item .item-graphic'), 0.8, { css: { className: '+=is-active' } }, 0);
      }
      movement_tl.to( $selector.not(':eq('+activeIndex+')'), 0.4, { css: { className: '-=is-active' } }, 0);
      movement_tl.to( $selector.eq(activeIndex), 0.45, { css: { className: '+=is-active' } }, 0);
    } else {
      movement_tl = new TimelineMax({ onUpdate: setPosition });
      movement_tl.to( $('.item .item-graphic'), 0.8, { css: { className: '-=is-active' } }, 0);
      movement_tl.to( $selector, 0.5, { css: { className: '-=is-active' } }, 0);
    }
    movement_tl.play();
}

function labelAnimation(type) {
    TweenMax.killTweensOf(label_tl);
    var label_tl = new TimelineMax();
    if( type == 'play') {
      label_tl.to( $selector.not(':eq('+activeIndex+')').find('.item-content'), 8, { opacity: 0, y: 200 }, 0);
      label_tl.to( $selector.eq(activeIndex).find('.item-content'), 1, { opacity: 1, y: 0 }, 0.8);
    } else {
      label_tl.to( $selector.find('.item-content'), 10, { opacity: 0, y: 200 }, 0);
    }
    label_tl.play();
}


function setPosition() {
  setItemPosition();
  setContainerHeight();
}

// Loop through and set the left position for each item
function setItemPosition() {
  // Get total width of items to center align them
  var itemTotalWidth = 0;
  $items.each(function(index) {
      itemTotalWidth += parseInt( $(this).outerWidth(true), 10);
  });
  var containerWidth = $container.offsetParent().width();
  var centerOffset = ($(window).width() - itemTotalWidth) / 2;
  var itemSize = getItemSize();
  
  if( viewport == 'showroom' ) {
    var leftPosition = 0;
    var ease = (is_zoomed == 1) ? Power1.easeOut : Sine.easeInOut;
    var positionDelay = (is_zoomed > 1) ? 0.4 : 0;
    var positionDuration = (is_zoomed == 1) ? zoomDuration : 0.6;
    $items.each(function(index) {
      var index = index;
      var relation = activeIndex - index;
      if( relation == 0 ) {
        var leftPosition = itemSize.minWidth / 2;
        positionDuration = (is_zoomed == 1) ? zoomDuration : 0.75;
      } else if ( relation == 1 ) {
        var leftPosition = (itemSize.minWidth / 2) * -1
      } else if ( relation > 1 ) {
        var leftPosition = ((itemSize.minWidth / 2) * -1) - (itemSize.minWidth * (relation - 1));
      } else if ( relation == -1 ) {
        var leftPosition = (containerWidth - (itemSize.minWidth / 2));
        positionDuration = (is_zoomed == 1) ? zoomDuration : 0.75;
      } else if ( relation < -1 ) {
        var leftPosition = (containerWidth - (itemSize.minWidth / 2)) - (itemSize.minWidth * (relation + 1));
      }
      
      TweenMax.to( $(this), positionDuration, {left: getPercentage(leftPosition, containerWidth), ease: ease, delay: positionDelay });

    });
  } else {
    $items.each(function(index) {
      var leftPosition = itemSize.minWidth * index + centerOffset;
      TweenMax.set( $(this), { left: getPercentage(leftPosition, containerWidth) });
    });
  }
}

function setContainerHeight() {
  var itemSize = getItemSize();
  // Set the tallest item height to the container
  $container.height( itemSize.maxHeight );
}

function getItemSize() {
  var itemHeights = $items.map(function() {
    return $(this).height();
  }).get();
  
  var itemWidths = $items.map(function() {
    return $(this).outerWidth(true);
  }).get();
  itemSize = {
    minWidth: Math.min.apply(null, itemWidths),
    maxWidth: Math.max.apply(null, itemWidths),
    minHeight: Math.min.apply(null, itemHeights),
    maxHeight: Math.max.apply(null, itemHeights),
  };
  return itemSize;
}

function init() {
  $selector.addClass('animation-slide');
  $selector.attr('data-is-selected', false);
  $selector.css({ position: 'absolute' });
  $container.wrapInner( "<div class='animation-viewport'></div>" );
  setPosition();
}

function getPercentage( a, b ) {
  var percent = 100*a/b;
  var percent = percent.toFixed(2) + '%';
  return percent;
}
              
            
!
999px

Console