123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              - grd = 240
- num = 12
- min = 60
 
.clock.all
  .w-num
    - for i in (1..num)
      .num data-num="#{i}" #{i}
  .w-num-g
    - for i in (1..num)
      - g = i * min / num
      .num-g data-num="#{g}" #{g}
  .grd
    - for i in (1..grd)
      .w-ms
        div class="ms-#{i}"
  .w-sec
    .sec-needle
  .w-min
    .min-needle
  .w-hour
    .hour-needle

  
            
          
!
            
              @import "compass"
$rem-base: 16px
$font-family-sans: "San Francisco Display", "Helvetica Neue", Helvetica, Arial, sans-serif
$main-color: #ffffff
$bg-color: #141515

// Clock
$nums: 12
$circ: 360deg
$radius: 30vh
$part: $circ / $nums

// Needles
$sec-needle-color: #e57513

// Graduation
$grd: 240
$deg-grd: 360 / $grd * 1deg

@function strip-unit($num)
  @return $num / ($num * 0 + 1)

@function convert-to-rem($value, $base-value: $rem-base)
  $value: strip-unit($value) / strip-unit($base-value) * 1rem
  @if $value == 0rem
    $value: 0
  @return $value

@function rem($values, $base-value: $rem-base)
  $max: length($values)
  @if $max == 1
    @return convert-to-rem(nth($values, 1), $base-value)
  $remValues: ()
  @for $i from 1 through $max
    $remValues: append($remValues, convert-to-rem(nth($values, $i), $base-value))
  @return $remValues
  
= abs-center
  display: flex
  justify-content: center
  align-items: center
  
html, body
  height: 100vh
  width: 100vw
body
  +abs-center
  background: $bg-color
  color: $main-color
  font-family: $font-family-sans
  text-rendering: geometricPrecision
  -webkit-font-smoothing: antialiased
  -moz-osx-font-smoothing: grayscale
  
.clock
  height: 0
  width: 0
  +abs-center
  position: relative
  &:after
    content: ''
    +translate(-50%, -50%)
    background: $bg-color
    box-shadow: 0 0 0 2vh $main-color
    border-radius: 99em
    position: absolute
    height: 2vh
    width: 2vh
    min-height: rem(4)
    min-width: rem(4)
  
.w-num .num
  position: absolute
  font-size: 8.5vh
  font-weight: 200
  +translate(-50%, -50%)
  @for $i from 0 through $nums
    $angle: $part * $i - $part * 3
    $top: sin($angle) * $radius 
    $left: cos($angle) * $radius 
    &:nth-child(#{$i})
      top: $top
      left: $left
.w-num-g .num-g
  position: absolute
  font-size: 5vh
  font-weight: 600
  color: rgba($main-color, .7)
  +translate(-50%, -50%)
  @for $i from 0 through $nums
    $angle: $part * $i - $part * 3
    $top: sin($angle) * ($radius + 17)
    $left: cos($angle) * ($radius + 17)
    &:nth-child(#{$i})
      top: $top
      left: $left
.grd
  position: relative
  .w-ms
    top: 0
    left: 0
    width: 0
    height: 0
    position: absolute
    [class*="ms-"]
      .all &
        &:before
          height: $radius / 14
          width:  0.5vh
          max-width: rem(3)
          min-width: rem(1)
          background: rgba($main-color, .25)
          border-radius: 99em
          position: absolute
          bottom: 0
          content: ''

    &:nth-child(4n)
      .all &
        [class*="ms-"]
          &:before
            background: rgba($main-color, .4)
    @for $i from 1 through $grd
      &:nth-child(4n)
        .all &
          [class*="ms-"]
            &:before
              height: $radius / 8
      &:nth-child(20n)
        .all &
          [class*="ms-"]
            &:before
              height: $radius / 6.4
              background: $main-color
          
      .ms-#{$i}
        transform: rotateZ($deg-grd) translateY($radius * 1.4)
      $deg-grd: $deg-grd + 360 / $grd * 1deg

  .w-sec, .w-min, .w-hour
    height: 0
    width: 0
    position: relative

.w-sec
  z-index: 99

.w-min
  z-index: 97
  
.sec-needle
  animation: tictac 60s linear infinite
  -webkit-filter: contrast(1)
  &:before
    height: $radius * 1.4
    border-radius: 99em
    bottom: 0
    width: 1vh
    max-width: rem(2)
    background: $sec-needle-color
    box-shadow: 0 5vh 0 0 $sec-needle-color
    position: absolute
    +translateX(-50%)
    content: ''
  &:after
    z-index: 99
    content: ''
    +translate(-50%, -50%)
    background: $bg-color
    box-shadow: 0 0 0 1vh $sec-needle-color
    border-radius: 50%
    position: absolute
    height: 2vh
    width: 2vh
    min-height: rem(4)
    min-width: rem(4)
  
.min-needle
  animation: tictac 3600s linear infinite
  -webkit-filter: contrast(2)
  &:before
    height: 7.6vh
    width: 1vh
    min-width: rem(1)
    background: $main-color
    position: absolute
    content: ""
    +translate(-50%, -100%)
  &:after
    content: ""
    +translateX(-50%)
    background: $bg-color
    height: $radius - 3
    width: 2vh
    border: 1vh solid $main-color
    border-radius: 2vh
    position: absolute
    bottom: 7vh

.hour-needle
  animation: tictac 43200s linear infinite
  -webkit-filter: contrast(2)
  &:before
    height: 7.6vh
    width: 1vh
    min-width: rem(1)
    background: $main-color
    position: absolute
    content: ""
    +translate(-50%, -100%)
  &:after
    content: ""
    +translateX(-50%)
    background: $bg-color
    height: $radius - 14
    width: 2vh
    border: 1vh solid $main-color
    border-radius: 2vh
    position: absolute
    bottom: 7vh

@keyframes tictac
  from
    transform: rotateZ(0deg) translate(-50%, -50%)
  to
    transform: rotateZ(360deg) translate(-50%, -50%)
            
          
!
            
              # JS is only used to get the current time.
# The needles are rotated when the page loads, the CSS does the rest to animate.

d = new Date
h = d.getHours()
m = d.getMinutes()
s = d.getSeconds()
ct = (v) ->
  t = v * 360 / 60
  t
ctm = (v) ->
  t = v * 360 / 60 + 6 * ct(s) / 360 # 1min = 6 deg
  t
cth = (v) ->
  t = v * 360 / 12 + 30 * ct(m) / 360 # 1h = 30 deg
  t
setTime = ->
  $('.w-sec').css 'transform', 'rotateZ(' + ct(s) + 'deg)'
  $('.w-min').css 'transform', 'rotateZ(' + ctm(m) + 'deg)'
  $('.w-hour').css 'transform', 'rotateZ(' + cth(h) + 'deg)'
$(document).ready ->
  setTime()
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console