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.

            
              <button>Reveal!</button>

	<div>
    <p>Transition any element on the page from any initial height to <code>auto</code> by adding or removing the attribute <code>reveal</code></p>

		<p>As when the stricken whale, that from the tub has reeled out hundreds of fathoms of rope; as, after deep sounding, he floats up again, and shows the slackened curling line buoyantly rising and spiralling towards the air; so now, Starbuck saw long coils of the umbilical cord of Madame Leviathan, by which the young cub seemed still tethered to its dam.</p>
	</div>

<button>Reveal!</button>

	<div>
    <p>Transition any element on the page from any initial height to <code>auto</code> by adding or removing the attribute <code>reveal</code></p>

		<p>As when the stricken whale, that from the tub has reeled out hundreds of fathoms of rope; as, after deep sounding, he floats up again, and shows the slackened curling line buoyantly rising and spiralling towards the air; so now, Starbuck saw long coils of the umbilical cord of Madame Leviathan, by which the young cub seemed still tethered to its dam.</p>
	</div>
            
          
!
            
              /*** Code for DEMO ***/

html, body {
  height: 100%;
}

button {
  margin-top: 20px;
  padding: 10px 12px;
}	

div {
		  height: 18px;
		  width: 50%;
		  padding: 10px;
		  overflow: hidden;
		  background: #ddd;
		  -webkit-transition: height 1s;
		  -moz-transition: height 1s;
      -ms-transition: height 1s;
		  transition: height 1s;
		}

div ~ div {
		  height: 3%;
}
            
          
!
            
              /*** Code for height: auto; transitioning ***/

(function(doc){
	
	/* feature detection for browsers that report different values for scrollHeight when an element's overflow is hidden vs visible (Firefox, IE) */
	var test = doc.documentElement.appendChild(doc.createElement('x-reveal-test'));
		test.innerHTML = '-';
		test.style.cssText = 'display: block !important; height: 0px !important; padding: 0px !important; font-size: 0px !important; border-width: 0px !important; line-height: 1px !important; overflow: hidden !important;';
	var scroll = test.scrollHeight || 2;
	doc.documentElement.removeChild(test);
	
	var loading = true,
		numReg = /^([0-9]*\.?[0-9]*)(.*)/,
		/* 2 out of 3 uses of this function are purely to work around Chrome's catastrophically busted implementation of auto value CSS transitioning */
		revealFrame = function(el, state, height){
			el.setAttribute('reveal-transition', 'frame');
			el.style.height = height;
			requestAnimationFrame(function(){
				el.setAttribute('reveal-transition', state);
				el.style.height = '';
			});
		},
		transitionend = function(e){
		  var node = e.target;
		  if (node.hasAttribute('reveal')) {
			if (node.getAttribute('reveal-transition') == 'running') revealFrame(node, 'complete', '');
		  } 
		  else {
			node.removeAttribute('reveal-transition');
			node.style.height = '';
		  }
		},
		animationstart = function(e){
		  var node = e.target,
			  name = e.animationName;   
		  if (name == 'reveal' || name == 'unreveal') {
			
			if (loading) return revealFrame(node, 'complete', 'auto');
			
			var style = getComputedStyle(node),
				offset = (Number(style.paddingTop.match(numReg)[1])) +
						 (Number(style.paddingBottom.match(numReg)[1])) +
						 (Number(style.borderTopWidth.match(numReg)[1])) +
						 (Number(style.borderBottomWidth.match(numReg)[1]));
						 
			if (name == 'reveal'){
			  node.setAttribute('reveal-transition', 'running');
			  node.style.height = node.scrollHeight - (offset / scroll) + 'px';
			}
			else {
				if (node.getAttribute('reveal-transition') == 'running') node.style.height = '';
				else revealFrame(node, 'running', node.scrollHeight - offset + 'px');
			}
		  }
		};
  doc.addEventListener('MSAnimationStart', animationstart, false);
	doc.addEventListener('animationstart', animationstart, false);
	doc.addEventListener('webkitAnimationStart', animationstart, false);
	doc.addEventListener('transitionend', transitionend, false);
  doc.addEventListener('MSTransitionEnd', transitionend, false);
	doc.addEventListener('webkitTransitionEnd', transitionend, false);
	
	/*
		Batshit readyState/DOMContentLoaded code to dance around Webkit/Chrome animation auto-run weirdness on initial page load.
		If they fixed their code, you could just check for if(doc.readyState != 'complete') in animationstart's if(loading) check
	*/
	if (document.readyState == 'complete') {
		requestAnimationFrame(function(){
			loading = false;
		});
	}
	else document.addEventListener('DOMContentLoaded', function(e){
		requestAnimationFrame(function(){
			loading = false;
		});
	}, false);
	
	/* Styles that allow for 'reveal' attribute triggers */
	var styles = doc.createElement('style'),
		t = 'transition: none; ',
		au = 'animation: reveal 0.001s; ',
		ar = 'animation: unreveal 0.001s; ',
		clip = ' { from { opacity: 0; } to { opacity: 1; } }',
		r = 'keyframes reveal' + clip,
		u = 'keyframes unreveal' + clip;
	
	styles.textContent = '[reveal] { -ms-'+ au + '-webkit-'+ au +'-moz-'+ au + au +'}' +
		'[reveal-transition="frame"] { -ms-' + t + '-webkit-' + t + '-moz-' + t + t + 'height: auto; }' +
		'[reveal-transition="complete"] { height: auto; }' +
		'[reveal-transition]:not([reveal]) { -webkit-'+ ar +'-moz-'+ ar + ar +'}' +
		'@-ms-' + r + '@-webkit-' + r + '@-moz-' + r + r +
		'@-ms-' + u +'@-webkit-' + u + '@-moz-' + u + u;
	
	doc.querySelector('head').appendChild(styles);
	
})(document);

/*** Code for DEMO ***/

		document.addEventListener('click', function(e){
	      if (e.target.nodeName == 'BUTTON') {
		    var next = e.target.nextElementSibling;
		    next.hasAttribute('reveal') ? next.removeAttribute('reveal') : next.setAttribute('reveal', '');
		  }
		}, false);
            
          
!
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.

Console