Pen Settings

HTML

CSS

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

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

              
                <button>toggle</button>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sodales tempus accumsan. Suspendisse sit amet convallis turpis. Fusce auctor porttitor lobortis. Maecenas luctus sem vel lacinia tempor. Morbi sit amet turpis id ligula accumsan mattis. Proin lacinia, ipsum a dignissim tempor, risus dui aliquam felis, non eleifend urna nisl sed mauris. Nullam congue vestibulum venenatis.</div>

<p>0, 0</p>
              
            
!

CSS

              
                div {
  display: none;
  overflow: hidden;
  width: 500px;
  padding: 20px;
  background: lightblue;
}
              
            
!

JS

              
                const div = document.querySelector('div');
const padding = '20px';
let isActive = false;



// -------------------------------- // --------------------------------

function logPadding() {
  
  gsap.set('p', { innerHTML: gsap.getProperty(div, "paddingTop") + ", " + gsap.getProperty(div, "paddingBottom") })
  
}

// -------------------------------- // --------------------------------





document.querySelector('button').addEventListener('click', () => {  
      
  if (isActive) {
    hide();
  } else {
    show();
  }
});

const hide = () => {
  isActive = false;
  gsap.to(div, {  
    height: 0, 
    paddingTop: 0, 
    paddingBottom: 0, 
    overwrite: 'auto', 
    duration: 0.5, 
    ease: 'power1.in',
    onComplete: () => onHideComplete(),
    onUpdate: () => logPadding()
  } );
}

const onHideComplete = () => {
  div.style.display = 'none';
  div.style.paddingTop = padding; //set back to original paddingTop before animation started?
  div.style.paddingBottom = padding; //set back to original paddingBottom before animation started?
}

const show = () => {
  isActive = true;
  div.style.display = 'block';
  div.style.height = 'auto';
  //const paddingTop = parseFloat(getComputedStyle(div).paddingTop); //best way to store this on first animation?
  const paddingTop = padding; 
  div.style.paddingTop = 0;
  //const paddingBottom = parseFloat(getComputedStyle(div).paddingBottom); //best way to store this on first animation?
  const paddingBottom = padding; 
  div.style.paddingBottom = 0;
  const targetHeight = div.offsetHeight; //best way to store this on first animation?
  div.style.height = 0;
  gsap.to(div, { 
    height: targetHeight, 
    paddingTop: paddingTop, 
    paddingBottom: paddingBottom,
    overwrite: 'auto', 
    duration: 0.5,
    ease: 'power1.out',
    onUpdate: () => logPadding()
  } );
}


              
            
!
999px

Console