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="intro-hint">
  <div class="arrow"></div>
</div>
<div class="pane">
  <div class="canvas">
    <div class="content">Hello world.</div>
  </div>
  <div class="crosses">
    <div class="cross"></div>
    <div class="cross"></div>
    <div class="cross"></div>
    <div class="cross"></div>
  </div>
</div>
<div class="star-field">
  <div class="layer"></div>
  <div class="layer"></div>
  <div class="layer"></div>
  <div class="layer"></div>
  <div class="layer"></div>
  <div class="layer"></div>
</div>
              
            
!

CSS

              
                body {
  background: black;
  position: absolute;
  top: 0; bottom: 0; left: 0; right: 0;
}

$width: 300px;
$height: 150px;

$cross-count: 4;
$cross-size: 10px;
$cross-stroke: 2px;
$cross-offset: ($cross-size - $cross-stroke) / 2;
  
$base-color: #fff;
$max-opacity: .4;

$base-duration: .3s;
$easing: ease-in-out;

@keyframes flicker {
  $frames: (
    0%: .01,
    40%: .3,
    50%: .1,
    70%: .4,
    90%: .1,
    100%: $max-opacity
  );
  @each $percent, $opacity in $frames {
    #{$percent} {
      $normalized-opacity: $opacity * (1.0 / $max-opacity);
      background: rgba($base-color, $opacity);
      color: rgba(darken($base-color, $percent), $normalized-opacity);
    }
  }
}

// Wraps all the pieces of the pane.
.pane {
  @extend %centered;
  overflow: visible;
  z-index: 10;
  // Canvas to contain the flickering pane.
  > .canvas {
    @extend %centered;
    width: 100%; height: 100%;
  }
  // Crosses are easier to access if wrapped.
  > .crosses {
    @extend %centered;
    width: $width; height: $height;
  }
  // Transition.
  // 0. Initial state.
  width: 1px; height: 1px;
  // 1. Perform flicker animation.
  $flicker-animation: flicker $base-duration steps(10, start);
  $flicker-delay-in: (5 * $base-duration);
  // 2. Perform size transition.
  $size-transition: (
    width $base-duration $easing,
    height $base-duration $easing
  );
  $size-transition-delay: 7/3 * $base-duration;
  transition: $size-transition;
  &.transition-in {
    transition-delay: $size-transition-delay;
    > .canvas { animation: $flicker-animation $flicker-delay-in normal forwards; }
  }
  &.transition-out {
    transition-delay: $size-transition-delay;
    > .canvas { animation: $flicker-animation reverse backwards; }
  }
  // 3. Arrive at active state.
  &.active {
    width: $width;
    height: $height;
    &:not(.transition-in) {
      > .canvas {
        background: rgba($base-color, $max-opacity);
      }
    }
  }
}

// FIXME: Confusing.
@mixin cross-transforms($extended: false) {
  $offset: $cross-size / 2;
  $center-offset: if($extended, 0, $cross-offset);
  $center-x: $width / 2;
  $center-y: $height / 2;
  $top:       if($extended, 0, $center-y);
  $left:      if($extended, 0, $center-x);
  $bottom:    if($extended, $height, $center-y);
  $right:     if($extended, $width,  $center-x);
  $extend-x:  if($extended, ($width / 2 - $offset),  0);
  $extend-y:  if($extended, ($height / 2 - $offset), 0);
  $borders-x: if($extended, (right left left right), (left right right left));
  $borders-y: if($extended, (bottom bottom top top), (top top bottom bottom));
  &:nth-child(1) { transform: translate($left,  $top); }
  &:nth-child(2) { transform: translate($right, $top); }
  &:nth-child(3) { transform: translate($right, $bottom); }
  &:nth-child(4) { transform: translate($left,  $bottom); }
  @for $i from 1 through $cross-count {
    &:nth-child(#{$i}) {
      &::before {
        $side: nth($borders-x, $i);
        border-#{$side}-width: $extend-x;
      }
      &::after {
        $side: nth($borders-y, $i);
        border-#{$side}-width: $extend-y;
      }
    }
  }
}

.cross {
  display: block;
  overflow: visible;
  position: absolute;
  // Extenders are pseudo-elements.
  $h-extender-selector: '&::before';
  $v-extender-selector: '&::after';
  $extenders-selector: '#{$h-extender-selector}, #{$v-extender-selector}';
  #{$extenders-selector} {
    background: $base-color;
    background-clip: padding-box; 
    content: ' ';
    display: block;
    overflow: visible;
    position: absolute;
  }
  #{$h-extender-selector} {
    width: $cross-size; height: $cross-stroke;
    top: $cross-offset;
  }
  #{$v-extender-selector} {
    width: $cross-stroke; height: $cross-size;
    left: $cross-offset;
  }
  // Transition.
  // 0. Initial state.
  #{$extenders-selector} {
    border: { width: 0; color: rgba($base-color, .5); style: solid; }
    transform: translate(-$cross-size / 2, -$cross-size / 2);
  }
  .pane & {
    // Start crosses in center.
    // Be explicit about property values for transitions.
    @include cross-transforms;
  }
  // 1. Perform position transition.
  transition: transform $base-duration;
  will-change: transform;
  .pane.transition-in & {
    @for $i from 1 through $cross-count {
      $staggered-delay: $base-duration + $i/10;
      &:nth-child(#{$i}) { transition-delay: $staggered-delay; }
    }
  }
  .pane.transition-out & {
    @for $i from 1 through $cross-count {
      $staggered-delay: 10/3 * $base-duration + $i/10;
      &:nth-child(#{$i}) { transition-delay: $staggered-delay; }
    }
  }
  // 2. Perform border-color transition.
  $border-color-transition: border-color $base-duration $easing;
  .pane:not(.transition-in):not(.transition-out) & {
    #{$extenders-selector} {
      border-color: rgba($base-color, .1);
    }
  }
  // FIXME: Multiple delays probably desired, but not possible without using `transition-property`.
  .pane.transition-in & {
    #{$extenders-selector} {
      $delay: 10/3 * $base-duration;
      transition-delay: $delay;
    }
  }
  .pane.transition-out & {
    #{$extenders-selector} {
      $delay: 5/3 * $base-duration;
      transition-delay: $delay;
    }
  }
  // 3. Perform border-width (extend) transition.
  $extend-transition: border-width (2/3 * $base-duration) ease-in;
  #{$extenders-selector} {
    transition: $border-color-transition, $extend-transition;
  }
  .pane.active & {
    @include cross-transforms(true);
  }
  // 4. When transitioning, reset if needed.
  $transitioning-in-context-selector: '.pane:not(.active):not(.transition-out) &';
  &:nth-child(2), &:nth-child(3) { // top right, bottom right
    #{$h-extender-selector} { right: -$cross-size; }
  }
  #{$h-extender-selector} {
    #{$transitioning-in-context-selector} { width: $cross-stroke; }
  }
  &:nth-child(3), &:nth-child(4) { // bottom right, bottom left
    #{$v-extender-selector} { bottom: -$cross-size; }
  }
  #{$v-extender-selector} {
    #{$transitioning-in-context-selector} { height: $cross-stroke; }
  }
}

// Content.
.content {
  @extend %centered;
  text-align: center;
  width: .7 * $width;
  &::selection {
    background: transparent;
  }
}

// Intro hint.
@keyframes pulsate {
  50% { opacity: 1; }
}
.intro-hint {
  @extend %centered;
  .arrow {
    $size: $cross-size / 2;
    $stroke: $cross-stroke;
    border: {
      color: $base-color;
      style: solid;
      width: 0 $stroke $stroke 0;
    }
    height: $size;
    transform: rotate(45deg);
    width: $size;
  }
  // Pulsate 3 times and extinguish.
  animation: pulsate 3s $easing 3;
  margin-top: -$height;
  opacity: 0;
}

// Starfield.
$sf-stars: 100;
$sf-depth: 600px;
$sf-height: 1080px;
$sf-layers: 6;
$sf-opacity: .9; // Amount that can change.
$sf-speed: 30s;
$sf-star-size: 4px;
$sf-width: 1920px;

@for $i from 1 through $sf-layers {
  // Near to far.
  $offset: $sf-depth - $i * $sf-depth;
  $min-opacity: 1 - $sf-opacity;
  $opacity: $min-opacity + $sf-opacity * (1 - $i / $sf-layers);
  @keyframes sf-fly-by-#{$i} {
    from {
      transform: translateZ($offset);
      opacity: $opacity;
    }
    to {
      transform: translateZ($sf-depth + $offset);
      opacity: $opacity / .75;
    }
  }
}
.star-field {
  width: 100%; height: 100%;
  opacity: .5;
  perspective: $sf-depth;
  .layer {
    $box-shadow: ();
    @for $i from 0 through $sf-stars {
      $center-x: $sf-width / 2;
      $center-y: $sf-height / 2;
      $x: random($sf-width);
      $y: random($sf-height);
      @while $x > $sf-width / 3 and $x < $sf-width * 2 / 3 and $y > $sf-height / 3 and $y < $sf-height * 2 / 3 {
        $x: random($sf-width);
        $y: random($sf-height);
      }
      $x: $x - $center-x;
      $y: $y - $center-y;
      $brightness: 75 + random(25);
      $box-shadow: $box-shadow, $x $y hsl(0,0, $brightness);
    }
    box-shadow: $box-shadow;
    transform-style: preserve-3d;
    position: absolute; top: 50%; left: 50%;
    height: $sf-star-size; width: $sf-star-size; border-radius: $sf-star-size / 2;
    @for $i from 1 through $sf-layers {
      // Near to far.
      &:nth-child(#{$i}) {
        animation: sf-fly-by-#{$i} $sf-speed linear infinite;
      }
    }
  }
}
              
            
!

JS

              
                $pane = $ '.pane'

activationTransition = (name, activeClass='active', duration=2.5) ->
  waitId = 'transition'
  return if $pane.isWaiting waitId
  isInTransition = 
    ($pane.hasClass(activeClass) and name is 'in') or 
    (not $pane.hasClass(activeClass) and name is 'out')
  return if isInTransition
  $pane.toggleClass activeClass, name is 'in' # FIXME (?)
  transitionClass = "transition-#{name}"
  $pane
    .addClass transitionClass
    .wait duration * 1000, waitId
    .done => $pane.removeClass transitionClass

$pane.hover(
  -> activationTransition('in'),
  -> activationTransition('out')
)

$pane.click (e) -> e.stopImmediatePropagation()
$('body').click -> activationTransition('out')
              
            
!
999px

Console