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

Auto Save

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

              
                <div class="folds">
  <div class="fold fold1">
    <div class="shadow"></div>
    <div class="content header">Public<br/>spaces</div>
    <div class="fold fold2">
      <div class="shadow"></div>
      <div class="content foldcontent">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>  
      </div>
    </div>
  </div>
</div>
<div class="mover">
  I am so attached to the element above...
</div>
<div class="container">
  <h3>Some more Text</h3>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolores, cum. Rem quaerat iusto assumenda voluptates dolores nulla, pariatur suscipit sapiente voluptate consequatur error. Ducimus inventore esse numquam, tempore vel aliquid.</p>
 </div>

<div class="controls">
  <input type="range" min="0" max="1" step="0.001" value="0" />
  <label><input type="checkbox" checked /> GPU</label>
  <button>Toggle</button>
</div>
              
            
!

CSS

              
                *{
  box-sizing: border-box;
}

html{
  font: 16px / 1.54 'Helvetica', sans-serif;
  background: #333;
}

body{
  margin: 50px auto 0;
  max-width: 700px;
}

.folds{
  position: relative;
  perspective: 2000px;
  perspective-origin: 50% 50%;
}

.fold{
  position: relative;
  transform-origin: 50% 0;
  transform-style: preserve-3d;
}

.shadow{
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background-image: linear-gradient(top, black, transparent);
  height: 50%;
}

.content{
  height: 200px;
}

.container{
  padding: 20px;
  background: #fff;
}

.mover{
  background: #f0f0f0;
  color: #333;
  padding: 20px;
}

.fold1{
  >.shadow{
    background: linear-gradient(bottom, black, transparent);
  }
  .content{
      background: url(https://farm3.staticflickr.com/2937/14371160993_186df4a083_c.jpg) 50% 50% no-repeat;
  }
}

.fold2{
  transform-origin: 50% 0;
  .content{
      background: #fff;
  }
}

.controls{
  position: absolute;
  top: 20px;
  left: 20px;
  width: 500px;
  color: #fff;

  input[type=range]{
    width: 300px;
  }
}

.header{
  text-transform: uppercase;
  text-align: left;
  padding: 20px;
  line-height: 1;
  font-size: 2em;
  color: #fff;
}

.foldcontent{
  padding: 20px;
}
              
            
!

JS

              
                // dom stuff
var d = document;
var control = d.querySelector('.controls input[type=range]');
var gpuEl = d.querySelector('.controls input[type=checkbox]');
var toggleEl = d.querySelector('.controls button');
var folds = d.querySelector('.folds');
var fold1 = d.querySelector('.fold1');
var fold2 = d.querySelector('.fold2');
var mover = d.querySelector('.mover');
var shadows = d.querySelectorAll('.shadow');

var ease = function (t, b, c, d) {
  if ((t/=d/2) < 1) return c/2*t*t + b;
  return -c/2 * ((--t)*(t-2) - 1) + b;
};

// settings
var foldHeight = fold2.offsetHeight;
var transform = Modernizr.prefixed('transform');
var percent = 0;
var isOpen = true;
var gpu = true;
// event listener for value changes on slider
control.addEventListener('input', function() {
  percent = Number(control.value);
});
// event listener for GPU change
gpuEl.addEventListener('change', function() {
  gpu = gpuEl.checked;
  fold(percent);
});
//event listener for toggle
toggleEl.addEventListener('click', function() {
  animate(percent, percent === 0 ? 1 : 0, 500);
});

function animate(from, to, duration) {
  var start = Date.now();
  var now, process, step;
  var anim = function() {
    now = Date.now();
    process = now - start;
    step = ease(process, from, (to-from), duration);
    
    if (process < duration) {
      fold(step);
      control.value = step;
      percent = step;
      requestAnimationFrame(anim);
    } else{
      fold(to);
      control.value = to;
      percent = to;
    }
  }
  
  anim();
}

// set the fold to a certain percentage
function fold(percent) {
  fold1.style[transform] = 'rotate3d(1,0,0,' + (percent * -90) + 'deg)';
  fold2.style[transform] = 'rotate3d(1,0,0,' + (percent * 180) + 'deg)';
  shadows[0].style.opacity = percent * 0.6;
  shadows[1].style.opacity = percent * 0.6;
 
  var visualFoldHeight = Math.cos(percent * Math.PI / 2) * foldHeight;
  
  folds.style['-webkit-perspective-origin'] =
  folds.style['-moz-perspective-origin'] =
  folds.style['perspective-origin'] = '50% ' + visualFoldHeight + 'px';
  if (gpu) { 
    // transform results in better performance
    mover.style[transform] = 'translate3d(0,' + (Math.floor((visualFoldHeight - foldHeight) * 2)) + 'px,0)';
    folds.style.height = 'auto';
  } else {
    // height is for better attachment of following elements
    folds.style.height = Math.floor(visualFoldHeight * 2) + 'px';
    mover.style[transform] = '';
  }};

// request animation frame synced loop that checks if the percent has changed
var lastPercent = -1;
var loop = function() {
  requestAnimationFrame(loop);
  if (lastPercent === percent) { return; }
  lastPercent = percent;
  fold(percent);
};

// start loop
loop();
              
            
!
999px

Console