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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="site-container">
  <div class="clock"></div>
</div>
              
            
!

CSS

              
                html,
body {
  background: black;
  color: #666;
  font-size: 5vh;
}
.site-container {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-size: cover;
}
.site-container:before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
}
.site-container.night:before {
  background: rgba(0,0,0,0.15);
}
.clock {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 15.4em;
}
.letter {
  width: 1.4em;
  text-align: center;
  display: block;
  float: left;
  text-transform: uppercase;
  font-family: Raleway, sans-serif;
  line-height: 1.5;
  transition: color 2s linear;
  color: rgba(255,255,255,0.4);
  text-shadow: 0 0 5vh rgba(0,0,0,0.8);
}
.letter.is-active {
  color: #FFF;
}
              
            
!

JS

              
                const $clock = $('.clock');
const $container = $('.site-container');
const letters = 'itdiswcbydraequarterhltwentywfivehalfptenytopastqlonineonesixthreefourfivetwoeightelevenseventwelvetenmsoclock';
const words = ['it','is','a','quarter','twenty','five','half','ten','to','past','nine','one','six','three','four','five2','two','eight','eleven','seven','twelve','ten2','oclock'];
const wordsByIndex = new Array(letters.length);
wordsByIndex.fill('');
const hrs = ['twelve', 'one', 'two', 'three', 'four', 'five2', 'six', 'seven', 'eight', 'nine', 'ten2', 'eleven'];

// turn letters into array
let lettersArray = letters.split('');

// get words by index
words.forEach(word => {
  let range = [0,0];
  if(word.indexOf('2') > 0) {
    let findWord = word.replace('2', '');
    range = [letters.lastIndexOf(findWord), letters.lastIndexOf(findWord) + findWord.length - 1];
  } else {
    range = [letters.indexOf(word), letters.indexOf(word) + word.length - 1];
  }
  for(let i=range[0]; i<=range[1]; i++) {
    wordsByIndex[i] = word;
  }
});

// add letters to clock
lettersArray.forEach((letter, index) => {
  let $letter = $('<span class="letter">' + letter + '</span>');
  $letter.addClass(wordsByIndex[index]);
  $clock.append($letter);
});

// do the updates
runLoop();
setInterval(() => {
  runLoop();
}, 5000);

function runLoop() {
  const date = new Date();
  let hr = date.getHours();
  const min = date.getMinutes();
  
  getBackgroundImage(hr);

  // 12hr time
  hr = hr > 12 ? hr - 12 : hr;

  reset();
  lightUp(['it', 'is']);
  lightUp(getPrefix(min));
  lightUp(getHour(hr, min));
  lightUp(getPostfix(min));
}

function getBackgroundImage(hr){
  let keyword = 'blue%20sky';
  if(hr < 4 || hr > 20) {
    keyword = 'night';
  } else if(hr < 8) {
    keyword = 'sunrise';
  } else if(hr > 16) {
    keyword = 'sunset';
  }
  //keyword = encodeURIComponent(keyword);
  let url = 'https://source.unsplash.com/category/nature/?' + keyword;
  
  // because we're using the simple unsplash api
  // and not doing any ajax, the browser won't
  // recognise that the image should change because
  // the endpoint url only changes as the
  // keywords do :(
  // a better implementation would be to use ajax
  // and retrieve an actual image path
  
  $container
    .css('background-image', 'none')
    .removeClass('night')
    .css('background-image', 'url(' + url + ')');
  
  if(keyword.indexOf('night') >= 0) {
    $container.addClass('night');
  }
}


function getPrefix(min) {
  min = round5(min);
  switch(min) {
    case 5:  return ['five', 'past'];
    case 10: return ['ten', 'past'];
    case 15: return ['a', 'quarter', 'past'];
    case 20: return ['twenty', 'past'];
    case 25: return ['twenty', 'five', 'past'];
    case 30: return ['half', 'past'];
    case 35: return ['twenty', 'five', 'to'];
    case 40: return ['twenty', 'to'];
    case 45: return ['a', 'quarter', 'to'];
    case 50: return ['ten', 'to'];
    case 55: return ['five', 'to'];
    case 0:
    case 60:
    default: return [''];
  }
}

function getPostfix(min) {
  min = round5(min);
  if(min === 0 || min === 60) {
    return 'oclock';
  } else {
    return '';
  }
}

function getHour(hour, min) {
  min = round5(min);
  if(min <= 30) {
    return hour === 12 ? hrs[0] : hrs[hour];
  } else if(hour === 11) {
    return hrs[0];
  } else {
    return hour === 12 ? hrs[1] : hrs[hour + 1];
  }
}

function lightUp(words) {
  if(!Array.isArray(words)) words = [words];
  words.forEach(word => {
    if(word.length > 0) {
      $('.' + word).addClass('is-active');
    }
  });
}

function reset() {
  $('.letter').removeClass('is-active');
}

function round5(num) {
  return Math.round(num/5) * 5;
}
              
            
!
999px

Console