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 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.

            
               <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 stupidity 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
🕑 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