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="copy__wrapper">
   <p>
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
     text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple lines but should be cut off text here that goes onto multiple
   </p>
</div>
            
          
!
            
              .copy__wrapper {
  background: #f00;
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
  transition: max-height .5s ease; 
  &.initialized {
    cursor: pointer;
    max-height: 200px;
  }
}
.copy__inner {
  overflow: hidden;
}

.copy__gradient {
  background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, white 100%);
  bottom: 0;
  height: 150px;
  left: 0;
  position: absolute;
  transition: bottom 1s ease;
  width: 100%;
  .reveal & {
    bottom: -150px;
    transition: bottom 2s ease;
  }
}
            
          
!
            
              // this function is for detecting transition event capabilities in the browser with jQuery - use $.support.csstransition in your if statements
$.support.csstransition = (function(){
    var thisBody = document.body || document.documentElement,
        thisStyle = thisBody.style,
        support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined;
    return support;
})();


// setup initial variables
var $copyWrapper = $(".copy__wrapper");

$copyWrapper.each(function() {
  // get height - have to set the variable here because Safari dies when getting height after a max-height is applied by a new class
  var initCopyHeight = $(this).height();
  
  // add a class to know we're doing stuff here
  $(this).addClass('initialized');
  
  // get copyHeight by cloning our element, grabbing the value, then removing it
  // this stupidify is because Safari barfs when a max-height is added via a class
  var $clone = $(this).clone().hide().appendTo('body');
  var copyHeight = parseFloat($clone.css('max-height'));
  $clone.remove();
  
  var $copyInner;
  
  // check to see if the text is long enough to even worry with this mess
  if (initCopyHeight < copyHeight) {
    $(this).css({ 'max-height': 'none' }); // if so, clear the max-height so their aren't any problems resizing
  } else {
    // add the inner div
    $(this).wrapInner('<div class="copy__inner"></div>');
    $copyInner = $(this).find('.copy__inner');
    
    // add the gradient overlay
    $(this).append('<div class="copy__gradient"></div>');
    
    // add click functionality
    $(this).click(function(){
      // setup variables
      var maxHeight;
      
      // if css transitions are supported, we'll use those
      if ($.support.csstransition) {
        maxHeight = { 'max-height': $copyInner.outerHeight(true) };
      } else { // if not, we'll override max-height so everything shows
        maxHeight = { 'max-height': 'none' };
      }

      // if the element has the 'reveal' class, we're setting it back to stock
      if ($(this).hasClass('reveal')) {
        $(this).css(maxHeight); // set the max-height to the height of the contents
        $(this).css('max-height'); // force the stupid browser to repaint
        $(this).css({ 'max-height': copyHeight, 'transition': '' }); // set the heights back to the default value
      } else {
        $(this).css(maxHeight);
        $(this).on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e){
          if(e.target === e.currentTarget) { // to keep multiple events from being fired (because of children elements with transitions)
            $(this).css({ 'max-height': 'none', 'transition': 'none' }); // set the max-height to none after the transition so page-resizing works
            $(this).off('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd'); // unbind the transition event so it doesn't fire when we collapse the div again
          }
        });
      }

      $(this).toggleClass("reveal");
    });
  }
});
            
          
!
999px
Loading ..................

Console