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

              
                <!--

Copyright © David Bushell | @dbushell | http://dbushell.com

-->

<div class="site">

  <button data-modal="nav" data-action="open" class="nav-open button button--circular" type="button"><span><i class="fa fa-bars"></i></span></button>

  
  <div class="site-content">
    
    <button data-modal="test" data-action="open" class="button button--circular" type="button"><span>Hello!</span></button>
    
  </div>

</div>
<!--/.site-->


<div class="overlay">
  <div class="overlay__ripple"></div>
</div>

<div class="modal-wrapper">
  
  <nav class="modal" data-modal="nav">
    <ul>
      <li><a href="http://dbushell.com/">Home</a></li>
      <li><a href="http://dbushell.com/about/">About</a></li>
      <li><a href="http://dbushell.com/showcase/">Portfolio</a></li>
      <li><a href="http://dbushell.com/responsive-design/">Services</a></li>
      <li><a href="http://dbushell.com/blog/">Blog</a></li>
      <li><a href="http://dbushell.com/contact/">Contact</a></li>
      <li><a href="https://twitter.com/dbushell"><i class="fa fa-twitter"></i> @dbushell</a></li>
    </ul>
    <a href="#main" class="button button--circular" data-action="close"><span><i class="fa fa-close"></i></span></a>
  </nav>
  
  <div class="modal" data-modal="test">
    <h1 style="font-size: 35px; line-height: 35px; margin: 0 0 14px 0;">I am David Bushell</h1>
    <p style="color:#919599; font-size: 17px; line-height: 21px; margin: 0 0 21px 0;"><a href="http://dbushell.com/">I freelance</a> for small businesses, start-ups, individuals, and fellow web agencies.</p>
    <div class="modal__footer">
      <button class="button" data-action="close" type="button">Awesome!</button>
    </div>
  </div>
  
</div>



              
            
!

CSS

              
                /*

Copyright © David Bushell | @dbushell | http://dbushell.com

*/

@function rem($px, $base: 16) {
    @return ($px / $base) + rem;
}

$color--white     : #fff;
$color--silver    : #f7f7f5;
$color--slate     : #494b4c;
$color--cream     : #f2f0e6;
$color--canvas    : #d9d7ce;
$color--highlight : #fff699;
$color--error     : #e54545;
$color--green     : #99cc66;
$color--blue      : #3d9ccc;
$color--dark-blue : #226181;

$color--grey       : #494b4d;
$color--dark-grey  : #303233;
$color--light-grey : #919599;

$color--line       : lighten(#b3b0aa, 15);
$color--light-line : lighten($color--line, 15);
$color--dark-line  : darken($color--line, 15);

html {
  height: 100%;
  color: $color--grey;
  font-family: 'Droid Serif', serif;
}

body {
  height: 100%;
  overflow-x: hidden;
  background: $color--cream;
  
  &.js-lock-scroll {
    overflow: hidden !important;
  }
  
  &.js-lock-pointer {
    pointer-events: none !important;
  }
}

a {
  color: $color--blue;
  text-decoration: none;
  
  &:focus, &:hover {
    color: $color--dark-blue;
  }
}

.site {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: visible;
  
/*  .js-lock-scroll & {
    overflow: hidden;
  }*/
}

.site-content {
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  padding-bottom: 100px;
}

.button {
  display: inline-block;
  appearance: none;
  outline: none;
  border: none;
  padding: 0;
  margin: 0;
  font-weight: bold;
  font-size: rem(14);
  line-height: rem(21);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  box-shadow: 1px 1px 2px rgba(0,0,0, 0.1);
  transition: color 150ms ease, box-shadow 150ms ease, background 300ms ease;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
  background: #fff;
  color: $color--blue;
  
  &:hover {
    color: $color--dark-blue;
    box-shadow: 1px 2px 3px rgba(0,0,0, 0.2);
  }
  
  &:active {
    color: #fff;
    transition: none;
    background: $color--blue;
  }
}

.button:not([class*='button--']) {
  padding: rem(7) rem(14);
}

.button--circular {
  position: relative;
  border-radius: 100%;
  padding: rem(14);
  
  span {
    display: block;
    height: 0;
    line-height: 0;
    margin: 50% 0 -50% 0;
    width: calc(100%);
    padding-bottom: calc(100%);
  }
  
  .fa {
    display: inline;
    line-height: 0;
  }
}

.nav-open {
  position: absolute;
  position: fixed;
  top: rem(14);
  left: rem(14);
}

.overlay,
.modal-wrapper {
  position: fixed;
  display: none;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}

.overlay {
  z-index: 10000;
  overflow: hidden;
  
  &.js-open {
    display: block;
  }
}

.overlay__ripple {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 100%;
  background: $color--blue;
  opacity: 0;
  transform-origin: 0 0;
  backface-visiblity: hidden;
  transform: scale(0) translate3d(-50%, -50%, 0);
  transition: opacity 600ms ease-in-out, transform 600ms cubic-bezier(0.7, 0, 0.6, 0.8);
  
  .overlay[data-modal="nav"] & {
    background: $color--green;
  }
  
  .js-animate-in & {
    opacity: 0.8;
    transform: scale(1) translate3d(-50%, -50%, 0);
  }
  
  .js-animate-done & {
    border-radius: 0;
    transform: none;
    transition: opacity 600ms ease-in-out;
  }
}

.modal-wrapper {
  z-index: 10001;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
  
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  
  .overlay:not(.js-open) + & {
    display: none;
  }
  
  .overlay.js-animate-in.js-animate-done + & {
    overflow: auto;
  }

  &:after, &:before {
    display: block;
    content: "";
  }
}

.modal {
  box-sizing: border-box;
  position: relative;
  display: none;
  max-width: 400px;
  margin: rem(28);
  padding: rem(21);
  padding-bottom: rem(63);
  background: #fff;
  box-shadow: 1px 2px 3px rgba(0,0,0, 0.1);
  opacity: 0;
  transform: translateZ(0);
  transition: opacity 300ms 150ms ease-in-out, transform 300ms 150ms ease-in-out;
}

// nav

.modal[data-modal="nav"] {
  transform: scale(0.5);
  transform-origin: 0 0;
  padding: rem(14) rem(28);
  width: 100%;
  max-width: rem(240);
  
  ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  
  li {
    display: block;
    border-bottom: 1px solid $color--line;
    
    &:last-child {
      border-bottom: 0;
    }
    
    a {
      display: block;
      font-size: rem(16);
      line-height: rem(28);
      padding: rem(7);
    }
  }
  
  .button[data-action="close"] {
    position: absolute;
    top: rem(-14);
    left: rem(-14);
  }
}

.overlay[data-modal="nav"] {
  
  & + .modal-wrapper {
    justify-content: flex-start;
    align-items: flex-start;
    flex-direction: row;
    
    &:after, &:before {
      display: none;
    }
  }
  
  // yeah the selectors and HTML configuration could be improved...
  
  &.js-open + .modal-wrapper .modal[data-modal="nav"] {
      display: block;
  }

  &.js-animate-in + .modal-wrapper .modal[data-modal="nav"] {
      opacity: 1;
      transform: scale(1);
  }
}

// test modal

.modal[data-modal="test"] {
  opacity: 0;
  transform: scale(0.95);
  
  .cssclippaths & {
    transform: translateZ(0);
    -webkit-clip-path: circle(0% at 50% 50%);
    transition: opacity 300ms ease-in-out, -webkit-clip-path 300ms cubic-bezier(0.7, 0, 0.6, 0.8);
  }

}

.overlay[data-modal="test"] {
  
  &.js-open + .modal-wrapper .modal[data-modal="test"] {
      display: block;
  }

  &.js-animate-in + .modal-wrapper .modal[data-modal="test"] {
      opacity: 1;
      transform: scale(1);
  }
}

.modal__footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: rem(14) rem(21);
  background: $color--canvas;
  text-align: right;
}
              
            
!

JS

              
                /*

Copyright © David Bushell | @dbushell | http://dbushell.com

*/

var $html = $(document.documentElement),
    $site = $('.site'),
		$body = $('body');

// animating clip-path is not playing nice in Safari
// http://browserhacks.com/

var hasCSSClipPaths = !!window.chrome && !/constructor/i.test(window.HTMLElement);

if (hasCSSClipPaths) {
  $html.addClass('cssclippaths');
}

$(window).scrollTop(0);

var $modal   = null,
		$overlay = $('.overlay'),
    $wrapper = $('.modal-wrapper'),
    $ripple  = $('.overlay__ripple');

function lockScroll(pointer)
{
//   var st = $(window).scrollTop();
  var w2, w1 = $html[0].clientWidth;
  $body.addClass('js-lock-scroll' + (pointer ? ' js-lock-pointer' : ''));
//   $site.css('margin-top', -st);  
  w2 = $html[0].clientWidth;
  // replace scrollbar with padding
  if (w2 > w1) {
	  $body.css('padding-right', w2 - w1);
  }
}

function unlockScroll()
{
//   var st = Math.abs(parseInt($site.css('margin-top'), 10));
//   $site.css('margin-top', 0);
  $body.css('padding-right', '').removeClass('js-lock-scroll js-lock-pointer');
//   $('html,body').scrollTop(st);
}

// return distance between two points
function dist(p1, p2)
{
  var xs = p2[0] - p1[0];
  var ys = p2[1] - p1[1];
  return Math.sqrt((xs * xs) + (ys * ys));
}

// return max width of a circle needed to cover a rectangle
function fillViewport(p1, width, height)
{
  // calc radius from centre to each corner
  var nw = dist(p1, [0,          0]),
      ne = dist(p1, [width,      0]),
      se = dist(p1, [width, height]),
      sw = dist(p1, [0,     height]);
  // return diameter required
  return 2 * Math.max(nw, ne, se, sw);
}

var openOverlay = function(btn, id)
{
  $modal = $('.modal[data-modal="' + id + '"]');

  lockScroll(true);
  
  requestAnimationFrame(function() {
  
    $overlay.addClass('js-open').attr('data-modal', id);
    var bounds = btn.getBoundingClientRect();

    // get viewport dimensions
    var vw = $(window).width(),
        vh = $(window).height();

    // get position of the button centre
    var p1 = [bounds.left + bounds.width / 2, bounds.top + bounds.height / 2];

    // calc max diameter required to fill viewport
    var diameter = fillViewport(p1, vw, vh);
    
    // pixels per second (animation speed)
    var pps = 3000;

    // scale minimum duration somewhat proportionally 
    var duration = 400 + (Math.round((diameter / pps) * 1000) * 0.5);

    $ripple.css({ 
      'transition-duration' : duration + 'ms',
      'width'  : diameter,
      'height' : diameter,
      'left'   : p1[0],
      'top'    : p1[1]
    });
    
    if (hasCSSClipPaths && id === 'test') {
      $modal.css('transition-duration', '300ms, ' + duration + 'ms');
      $modal.css('-webkit-clip-path', 'circle(' + (diameter/2) + 'px at 50% 50%)');
    }

    requestAnimationFrame(function() {
      $overlay.addClass('js-animate-in');

      $ripple.one('transitionend', function() {
        $overlay.addClass('js-animate-done');
        $body.removeClass('js-lock-pointer');
        $ripple.removeAttr('style');
      	
      })
    });
    
  });
};

var closeOverlay = function() {
  $body.addClass('js-lock-pointer');
  
  requestAnimationFrame(function() {
    $modal.removeAttr('style');
  	$overlay.removeClass('js-animate-in');
  });  

  $ripple.one('transitionend', function() {
    $wrapper.scrollTop(0);
  	$overlay.removeClass('js-open js-animate-done').removeAttr('data-modal');
    unlockScroll();
  });
}

$('[data-modal][data-action="open"]').on('click', function() {
  var btn = this;
  requestAnimationFrame(function() {
	  openOverlay(btn, $(btn).data('modal'));
  });
});

$overlay.on('click', function() {
  requestAnimationFrame(function() {
    closeOverlay();
  });
});

$wrapper.on('click', function(e) {
  var $target = $(e.target);
  if ($target.hasClass('modal')) return;
  if ($target.parents('.modal').length && $target.data('action') !== 'close') {
    if (!$target.parents('[data-action="close"]').length) {
    	return;
    }
  }
  e.preventDefault();
  requestAnimationFrame(function() {
    closeOverlay();
  });
});

// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
 
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
 
// MIT license
 
(function() {
    var lastTime = 0;
    var vendors = ['ms', 'moz', 'webkit', 'o'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] 
                                   || window[vendors[x]+'CancelRequestAnimationFrame'];
    }
 
    if (!window.requestAnimationFrame)
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };
 
    if (!window.cancelAnimationFrame)
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
}());
              
            
!
999px

Console