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

              
                -var lines = [
-  ["it's", 'quarter', 'half'],
-  ['ten', 'twenty', 'five'],
-  ['to', 'past', 'one', 'two'],
-  ['three', 'four', 'five'],
-  ['six', 'seven', 'eight'],
-  ['nine', 'ten', 'eleven'],
-  ['twelve', "o'clock"]
-]

.clock
  .rivets.top
  .content
    each line in lines
      .line
        each word in line
          span.word= word
    .dots
      each index in [1, 2, 3, 4]
        span.dot= index
  .rivets.bottom

#ticker.ticker
              
            
!

CSS

              
                // reset
@import '//codepen.io/chrisdothtml/pen/ojLzJK.css'

// settings
clock-size = 500px
clock-gutter = 65px
rivet-size = 17px
rivet-margin = 10px
dot-size = 15px
dot-margin = 15px

// general reference
line-count = 7
dot-count = 4

$rivet
  background-color: #efefef
  width: rivet-size
  height: rivet-size
  position: absolute
  border-radius: 50%
  box-shadow: -3px -3px 5px 0 rgba(0, 0, 0, .4) inset

$item
  opacity: .2
  transition: all 0.3s

  &.active
    opacity: 1

$word
  @extends $item
  font-family: 'Titillium Web', sans-serif
  font-size: 43px
  color: #fff
  text-transform: uppercase
  
  &.active
    text-shadow: 0px 0px 10px rgba(255, 255, 255, .4)

$dot
  @extends $item
  background-color: #fff
  width: dot-size
  height: dot-size

html
  width: 100%
  min-width: clock-size + 50px
  height: 100%
  min-height: clock-size + 70px
  position: relative

body
  background: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/216995/wood_pattern.png)

.clock
  background-color: #212121
  width: clock-size
  height: clock-size
  margin: 20px auto 0
  position: relative
  z-index: 2
  border-radius: 8px
  box-shadow: 5px 5px 15px 2px rgba(0, 0, 0, .4)

  .content
    width: 100%
    height: 100%
    padding: clock-gutter
    position: absolute

    .line
      display: flex
      justify-content: space-between

      .word
        @extends $word
        display: block
        line-height: ((clock-size - (clock-gutter * 2)) / line-count)

    .dots
      	display: flex
      	justify-content: space-between
      	width: (dot-size * dot-count) + (dot-margin * (dot-count - 1))
      	position: absolute
      	bottom: (clock-gutter / 2)
      	left: 50%
      	transform: translate(-50%, 50%)

      .dot
        @extends $dot
        display: block
        // hide text
        text-indent: 100%
        white-space: nowrap
        overflow: hidden

  .rivets
    &:before,
    &:after
      @extends $rivet
      content: ''

    &:before
      left: rivet-margin

    &:after
      right: rivet-margin

    &.top
      &:before,
      &:after
        top: rivet-margin

    &.bottom
      &:before,
      &:after
        bottom: rivet-margin

.ticker
  width: 100%
  line-height: 1
  font-size: 25px
  color: #c59e62
  text-align: center
  position: absolute
  bottom: 5px
  z-index: 1
  text-shadow: -1px -1px 1px #2b2418

              
            
!

JS

              
                const $items = getItems()
const permItems = ['its']

/**
 * @returns {object}
 */
function getItems () {
  const result = {}
  const dots = '.clock .content .dots .dot'
  const words = '.clock .content .line .word'

  $(words).each(function () {
    const $word = $(this)
    let label = $word.text().replace('\'', '')

    if (result[label]) {
      label += '2'
    }

    result[label] = $word
  })

  $(dots).each(function () {
    const $dot = $(this)
    const label = $dot.text()

    result['dot' + label] = $dot
  })

  result.all = $(`${dots}, ${words}`)
  return result
}

/**
 * Updates time ticker
 */
function updateTicker () {
  const time = moment().format('hh:mm:ss')

  $('#ticker').text(time)
}

/**
 * Resets and activates new items
 */
function updateClock (items) {
  $items.all.removeClass('active')

  items.forEach(item => {
    $items[item].addClass('active')
  })
}

/**
 * Determines the proper hour item(s) to use
 *
 * @returns {array}
 */
function getHourItems (hour, minutes) {
  const result = []
  const map = { 1: 'one', 2: 'two', 3: 'three', 4: 'four',
    5: 'five2', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine',
    10: 'ten2', 11: 'eleven', 12: 'twelve' }

  // direction only applies to minutes > 4
  if (minutes > 4) {
    let direction

    if (minutes > 34) {
      direction = 'to'

      // use next hour
      if (hour === 12) {
        hour = 1
      } else {
        hour++
      }
    } else {
      direction = 'past'
    }

    result.push(direction)
  }

  result.push(map[hour])
  return result
}

/**
 * Determines the proper minute item(s) to use
 *
 * @returns {array}
 */
function getMinuteItems (minutes) {
  const map = {
    '0-4': ['oclock'],
    '5-9,55-59': ['five'],
    '10-14,50-54': ['ten'],
    '15-19,45-49': ['quarter'],
    '20-24,40-44': ['twenty'],
    '25-29,35-39': ['twenty', 'five'],
    '30-34': ['half']
  }
  let result = []

  // each map range
  mapLoop:
  for (let ranges in map) {
    let items = map[ranges]
    let rangesArr = ranges.split(',')

    // each 'n-n' segment
    for (let i = 0; i < rangesArr.length; i++) {
      let range = rangesArr[i].split('-')
      let floor = range[0]
      let ceil = range[1]

      // minutes match map range
      if (minutes >= floor && minutes <= ceil) {
        result = result.concat(items)

        // dots for overflow minutes
        if (minutes > floor) {
          let remainder = minutes - floor

          for (let i = 1; i <= remainder; i++) {
            result.push('dot' + i)
          }
        }

        break mapLoop
      }
    }
  }

  return result
}

/**
 * Determines what items need to be activated for the
 * current time
 *
 * @returns {array}
 */
function getTimeItems () {
  const time = moment()
  const hour = Number(time.format('h'))
  const minutes = time.minutes()

  return []
    .concat(getHourItems(hour, minutes))
    .concat(getMinuteItems(minutes))
    .concat(permItems)
}

/**
 * Updates clock with current time
 */
function update () {
  const newItems = getTimeItems()

  updateClock(newItems)
  updateTicker()
}

// start ticking
new Tock({
  interval: 1000,
  callback: update
}).start()

              
            
!
999px

Console