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

              
                
<main>
  <div style="display:none">
    <div id="top-test-anim" class="num-anim top-anim" style="display:none;">
      <div class="top-half-num">2</div>
    </div>
    <div id="bottom-test-anim" class="num-anim bottom-anim" style="display:none;">
      <div class="bottom-half-num">
        <div class="dropper">3</div></div>
    </div>
  </div>
  <canvas id="my-canvas"></canvas>
  <div id="clock">
    <div class="time-container hours">
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="hour-tens-top">1</span>
        <span class="num bottom" id="hour-tens-bottom">
          <div class="bottom-container">1</div></span>
          <div class="swapper">
            <div id="top-hour-tens-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">8</div>
            </div>
            <div id="bottom-hour-tens-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">9</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="hour-ones-top">3</span>
        <span class="num bottom" id="hour-ones-bottom">
          <div class="bottom-container">3</div></span>
          <div class="swapper">
            <div id="top-hour-ones-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">8</div>
            </div>
            <div id="bottom-hour-ones-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">9</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
    </div>
    <div class="time-container minutes">
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="minute-tens-top">4</span>
        <span class="num bottom" id="minute-tens-bottom">
          <div class="bottom-container">4</div></span>
          <div class="swapper">
            <div id="top-minute-tens-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">8</div>
            </div>
            <div id="bottom-minute-tens-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">9</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="minute-ones-top">3</span>
        <span class="num bottom" id="minute-ones-bottom">
          <div class="bottom-container">3</div></span>
          <div class="swapper">
            <div id="top-minute-ones-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">8</div>
            </div>
            <div id="bottom-minute-ones-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">9</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
    </div>
    <div class="time-container seconds">
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="second-tens-top">5</span>
        <span class="num bottom" id="second-tens-bottom">
          <div class="bottom-container">5</div></span>
          <div class="swapper">
            <div id="top-second-tens-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">8</div>
            </div>
            <div id="bottom-second-tens-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">9</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
      <div class="digit">
        <div class="fade">&nbsp;</div>
        <span class="num top" id="second-ones-top">3</span>
        <span class="num bottom" id="second-ones-bottom">
          <div class="bottom-container">2</div></span>
          <div class="swapper">
            <div id="top-second-ones-anim" class="num-anim top-anim" style="display:none;">
              <div class="top-half-num">2</div>
            </div>
            <div id="bottom-second-ones-anim" class="num-anim bottom-anim" style="display:none;">
              <div class="bottom-half-num">
                <div class="dropper">3</div></div>
            </div>
        </div>
        <div class="ring ring-left"></div>
        <div class="ring ring-right"></div>
      </div>
    </div>
  </div>
</main>
              
            
!

CSS

              
                @import "lesshat";

html {
  height: 100%;
}
body {
  overflow: hidden;
  color: rgba(248, 233, 214, 1);
  font-family: "Lucida Sans Typewriter", "Lucida Console", Monaco, "Bitstream Vera Sans Mono", monospace;
  font-size: 110px;
  .background-image( ~'radial-gradient(50% 50%, circle, rgb(103, 114, 140) 0%, rgb(69, 76, 94) 36%, rgb(34, 37, 46) 90%)');
  height: 100%;
  margin: 0px;
  padding: 0px;
  main {
    height: 100%;
  background-size: 18px 18px;
  .background-image( ~"linear-gradient(-45deg, transparent 0%, transparent 40%, rgba(0, 0, 0, .2) 40%, rgba(0, 0, 0, .2) 50%, transparent 50%, transparent 90%, rgba(0, 0, 0, .2) 90%);");
    .num-anim {
      display: block;
      position: absolute;
      top: 0px;
      left: 0px;
      height: 130px;
      width: 89px;
      .top-half-num, .bottom-half-num {
        .background-image( ~"linear-gradient(180deg, rgba(68, 75, 93, 1), rgba(46, 50, 62, 1) 100%)");
        text-align: center;
        overflow: hidden;
        padding-top: 0px;
      }
      .top-half-num {
        height: 50%;
      }
      .bottom-half-num {
        margin-top: 0px;
        height: 50%;
        margin-top: 65px;
        .dropper {
          margin-top: -68px;
        }
        background-color: rgba(46, 50, 62, 1);
        background-image: none;
      }
      &.bottom-anim {
        left: 0px;
        top: 5px;
        .transform(~"perspective(80px) rotateX(90deg) rotateY(0deg);");
        &.down {
          .transform(~"perspective(80px) rotateX(0deg) rotateY(0deg)");
          .transition(0.25s);
          .transition-delay(0.25s);
        }
      }
      &.top-anim {
        .transform(~"perspective(80px) rotateX(0deg) rotateY(0deg);");
      
        &.up {
          .transform(~"perspective(80px) rotateX(-90deg) rotateY(0deg)");
          .transition(0.25s);
        }
      }
    }
    canvas {
      height: 100%;
      width: 100%;
      background-color: transparent;
    }
    #clock {
      position: absolute;
      top: 50%;
      left: 50%;
      margin: -75px 0 0 -372.5px;
      height: 150px;
      width: 745px;
      .time-container {
        float: left;
        width: 220px;
        height: 150px;
        margin: 0 0 0 20px;
        border: 1px solid #000;
        .border-radius(10px);
        background: rgba(24, 24, 40, .50);
        .box-shadow(~"0 2px 0px rgba(255, 255, 255, .25), inset 0 2px 0px rgba(0, 0, 0, .25)");
         .num {
          position: absolute;
          top: 0px;
          left: 00px;
          display: inline-block;
          z-index: 1;
          height: 50%;
          overflow: hidden;
          width: 100%;
          .box-shadow(~"0 2px 0px rgba(0, 0, 0, .25), inset 0 2px 0px rgba(255, 255, 255, .25)");
          &.bottom {
            top: 53%;
            height: 46%;
            .bottom-container {
              margin-top: -76%;
            }
          }
         }
         .fade {
          position: absolute;
          top: -105px;
          left: -41px;
          width: 100%;
          height: 200%;
          background-color: transparent;
          .background-image( ~"linear-gradient(0deg, transparent 35%, rgba(255, 255, 255, .2), rgba(255, 255, 255, .5))");
          .rotate(45deg);
          z-index: 2;
         }
        .digit {
          position: relative;
          float: left;
          width: 88px;
          height: 130px;
          margin: 11px 0 0 15px;
          .border-radius(5px);
          text-align: center;
          text-shadow: rgba(255,255,255, 1) 0px -3px 0px, rgba(0,0,0,1) 0px 3px 0px;
          background-color: rgba(53, 58, 72, 1);
          .box-shadow(~"0 2px 0px rgba(0, 0, 0, .25), inset 0 2px 0px rgba(255, 255, 255, .25), 2px 2px 3px rgba(0, 0, 0, 1), -2px -2px 3px rgba(0, 0, 0, 1), 2px -2px 3px rgba(0, 0, 0, 1), -2px 2px 3px rgba(0, 0, 0, 1)");
          .background-image( ~"linear-gradient(180deg, rgba(68, 75, 93, 1), rgba(46, 50, 62, 1) 100%)");
          overflow: hidden;
          &::after {
            content: " ";
            border: 2px solid rgba(0, 0, 0, .15);
            width: 80px;
            margin-top: 3px;
            height: 121px;
            .border-radius(5px);
            display: inline-block;
          }
          .ring {
            position: absolute;
            top: 58px;
            left: 5px;
            height: 20px;
            width: 7px;
            background-color: rgba(125, 125, 125, 1);
            .box-shadow(~"0 2px 0px rgba(0, 0, 0, .25), inset 0 2px 0px rgba(255, 255, 255, .25), 2px 2px 1px rgba(0, 0, 0, .5), -2px -2px 1px rgba(0, 0, 0, .5), 2px -2px 1px rgba(0, 0, 0, .5), -2px 2px 1px rgba(0, 0, 0, .5)");
          .background-image( ~"linear-gradient(180deg, rgba(205, 205, 205, 1), rgba(46, 50, 62, 1) 100%)");
            z-index: 3;
            &.ring-right {
              left: 76px;
            }
            .border-radius(8px);
          }
        }
      }
    }
  }
}
.swapper {
  position: relative;
  z-index: 2;
}


       
              
            
!

JS

              
                var CHANCE_SPEC, x, y;

CHANCE_SPEC = 60;
x = 0;
y = 0;

function rand(min, max) {
  return Math.floor(Math.random() * (max - min + 1) - min);
}

function drawSpec(data, x, y, w) {
    var index;
  
    index = (x + y * w) * 4;

    data.data[index + 0] = 0;
    data.data[index + 1] = 0;
    data.data[index + 2] = 0;
    data.data[index + 3] = 30;
}

function drawPattern(canvas, ctx, data) {
  var w, h;
  w = canvas.width;
  h = canvas.height;
  while (x < w) {
    if (rand(1, 100) < CHANCE_SPEC) {
      drawSpec(data, x, y, w);
    }
    x++;
  }
  if (x === w) {
    x = 0;
    y++;
  }
  if (y === h) {  
    ctx.putImageData(data, 0, 0);
    return;
  }
  drawPattern(canvas, ctx, data);
}

function main() {
  var canvas, ctx, data;
  
  console.log('starting1');
  canvas = document.getElementById('my-canvas');
  ctx = canvas.getContext('2d');
  data = ctx.getImageData(0, 0, canvas.width, canvas.height);
  drawPattern(canvas, ctx, data);
  updateTime();
}

function updateTime() {
  var currentTime, seconds, minutes, hours, times, i;
  currentTime = new Date();
  times = {
    'second': currentTime.getSeconds(),
    'minute': currentTime.getMinutes(),
    'hour': currentTime.getHours()
  };
  for (type in times) {
    if (times.hasOwnProperty(type)) {
      setTimes(type, timeToString(times[type]));
    }
  }
  setTimeout(updateTime, 1000);
}

function timeToString(currentTime) {
  var t;
  t = currentTime.toString();
  if (t.length === 1) {
    return '0' + t;
  }
  return t;
}

function getPreviousTime(type) {
  return $('#' + type + '-top').text();
}

function setTimes(type, timeStr) {
  setTime(getPreviousTime(type + '-tens'), 
    timeStr[0], type + '-tens');
  setTime(getPreviousTime(type + '-ones'),
    timeStr[1], type + '-ones');
}

function setTime(previousTime, newTime, type) {
  if (previousTime === newTime) {
    return;
  }
  setTimeout(function() {
    $('#' + type + '-top').text(newTime);
  }, 150);
  setTimeout(function() {
  $('.bottom-container',
    $('#' + type + '-bottom')).text(newTime);
  }, 365);
  animateTime(previousTime, newTime, type);
}

function animateTime(previousTime, newTime, type) {
  var top, bottom;
  top = $('#top-' + type + '-anim');
  bottom = $('#bottom-' + type + '-anim');
  $('.top-half-num', top).text(previousTime);
  $('.dropper', bottom).text(newTime);
  top.show();
  bottom.show();
  $('#top-' + type + '-anim').css('visibility', 'visible');
  $('#bottom-' + type + '-anim').css('visibility', 'visible');
  animateNumSwap(type);
  setTimeout(function() {
    hideNumSwap(type);
  }, 365);
}

function animateNumSwap(type) {
  $('#top-' + type + '-anim').toggleClass('up');
  $('#bottom-' + type + '-anim').toggleClass('down');
}

function hideNumSwap(type) {
  $('#top-' + type + '-anim').toggleClass('up');
  $('#bottom-' + type + '-anim').toggleClass('down');
  $('#top-' + type + '-anim').css('visibility', 'hidden');
  $('#bottom-' + type + '-anim').css('visibility', 'hidden');
}

$(document).ready(main);


window.requestAnimFrame = (function(callback){ 
    return window.requestAnimationFrame || 
        window.webkitRequestAnimationFrame || 
        window.mozRequestAnimationFrame || 
        window.oRequestAnimationFrame || 
        window.msRequestAnimationFrame || 
        function(callback){ window.setTimeout(callback, 1000 / 60); }
})();

              
            
!
999px

Console