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

              
                
<h1>
  <span>
    Daylight Cycles
    <i>of</i>
    <b>Earth</b>
  </span>
</h1>
  
<div class="earth-container">
  <div
    class="globe"
    onmouseover="isHover = true"
    onmousemove="hoverOrbit(event)"
    onmouseout="isHover = false"
  >
    <div
      id="northLabel"
      class="day-label north-label"
    ></div>
    <div
      id="southLabel"
      class="day-label south-label"
    ></div>
  </div>
  <div class="shadow">
    <span
      id="label"
      class="label"
    ></span>
  </div>
</div>

<div
  class="orbit-container"
  onmouseover="isHover = true"
  onmousemove="hoverOrbit(event)"
  onmouseout="isHover = false"
>
  <div class="sun"></div>
  <div class="earth"></div>
  <div class="labels">
    <div>
      <span> Solstice </span>
      <span> Equinox </span>
      <span> Solstice </span>
    </div>
    <div>
      <span> Dec 21<small>st</small> </span>
      <span>
        Mar 20<small>th</small>
        <br/>
        Sep 23<small>rd</small>
      </span>
      <span> Jun 21<small>st</small> </span>
    </div>
  </div>
</div>
              
            
!

CSS

              
                $angMax: 23.4;

body {
  margin: 0;
  color: #fff;
  font-size: 16px;
  font-family: 'Times New Roman';
  font-weight: 100;
  font-style: italic;
  background: #222;
}

h1 {
  margin-top: 5vh;
  color: #fff;
  text-align: center;
  font-size: 32px;
  font-style: normal;
  font-weight: 100;
  letter-spacing: 2px;
  
  i {
    font-size: 14px;
    vertical-align: 35%;
  }
  
  b {
    font-family: Helvetica;
  }
  
  span {
    display: inline-block;
    border-bottom: 1px solid #fff8;
    height: 33px;
    padding: 0 6px;
  }
}

.earth-container {
  $earthWidth: 380px;
  @keyframes rotate {
    from {
      background-position: 0 0;
    }
    to {
      background-position: #{$earthWidth * 2.5} 0;
    }
  }
  
  position: relative;
  margin: 80px 0 120px calc(50% - #{$earthWidth / 2});
  height: $earthWidth;
  background:
    linear-gradient(
      90deg,
      #222 #{$earthWidth / 2},
      #0000 #{$earthWidth / 2}
    ),
    linear-gradient(#0000 0, #111 0.5%, #111 98.5%, #0000 100%);
  cursor: pointer;
  
  .globe {
    position: absolute;
    width: $earthWidth;
    height: 100%;
    border-radius: 100%;
    background: url('https://upload.wikimedia.org/wikipedia/commons/6/69/Peters_projection%2C_white_%26_grey.png') 0 0 / 250% 100%, #008;
    animation: rotate 40s infinite linear;
    transform: rotate(
      calc(#{-$angMax}deg * var(--ang))
    );

    &:before,
    &:after {
      content: '';
      position: absolute;
      inset: 100% 50% -80px;
      width: 1px;
      border-left: 2px solid #fff8;
    }
    
    &:after {
      inset: -40px 50% 100%;
    }
  }
  
  .day-label {
    position: absolute;
    left: 0;
    z-index: 10;
    width: 50px;
    text-align: right;
    color: #fff;
    pointer-events: none;

    &:after {
      content: '';
      position: absolute;
      inset: 50% -#{$earthWidth * 0.68} 50% 145%;
      border-bottom: 2px dotted #fff;
      border-top: 2px dotted #383977;
      z-index: 10;
    }

    &.north-label {
      top: 8%;
    }

    &.south-label {
      bottom: 10%;
    }
  }

  .shadow {
    position: absolute;
    width: $earthWidth;
    height: 100%;
    z-index: 20;
    pointer-events: none;

    &:before {
      content: '';
      position: absolute;
      inset: -200px 0;
      clip-path: circle(#{($earthWidth / 2) + 1px});
      box-shadow: inset -180px 0 20px 0 #000d;
      border-radius: 100%;
    }

    &:after {
      content: '';
      position: absolute;
      inset: 100% 50% -80px;
      width: 1px;
      border-left: 2px solid #fff8;
    }

    .label {
      position: absolute;
      height: 16px;
      width: fit-content;
      bottom: -55px;
      left: calc(50% + 8px);
      color: #fff;

      &:before {
        content: '';
        position: absolute;
        bottom: 22px;
        left: $earthWidth * -0.625;
        padding: $earthWidth * 0.6;
        border: 2px dotted #fff8;
        border-radius: 100%;
        clip-path: circle(
          calc(
            #{2 * $angMax}px *
            max(var(--ang), -1 * var(--ang))
          ) at
          calc(
            50% + (
              #{2 * $angMax}px * var(--ang)
            )
          ) 100%
        );
      }
    }
  }
}

.orbit-container {
  position: relative;
  width: 650px;
  margin: 0 auto;
  max-width: calc(100vw - 80px);
  cursor: pointer;
  
  &:before,
  &:after {
    content: '';
    position: absolute;
    inset: 37px 0 auto 0;
    height: 8px;
    border-radius: 100%;
    border: 2px dashed #fff8;
  }
  
  &:before {
    border-bottom-width: 0;
    z-index: -10;
  }
  
  &:after {
    border-top-width: 0;
    z-index: 5;
  }
  
  .earth {
    $c-earth: #8686bd;
    $c-earth-d: #393877;
    
    @keyframes earthBg {
      0%    { background: linear-gradient(90deg, $c-earth 50%, $c-earth-d 50%);  }
      49.9% { background: linear-gradient(90deg, $c-earth 50%, $c-earth-d 50%);  }
      50%   { background: linear-gradient(-90deg, $c-earth 50%, $c-earth-d 50%); }
      100%  { background: linear-gradient(-90deg, $c-earth 50%, $c-earth-d 50%); }
    }
	
    @keyframes earthFg {
      0% {
        transform: scale(1, 1);
        background: $c-earth;
      }
      24.9% {
        transform: scale(0, 1);
        background: $c-earth;
      }
      25% {
        transform: scale(0, 1);
        background: $c-earth-d;
      }
      49.9% {
        transform: scale(-1, 1);
        background: $c-earth-d;
      }
      50% {
        transform: scale(1, 1);
        background: $c-earth-d;
      }
      74.9% {
        transform: scale(0, 1);
        background: $c-earth-d;
      }
      75% {
        transform: scale(0, 1);
        background: $c-earth;
      }
      100% {
        transform: scale(-1, 1);
        background: $c-earth;
      }
    }
    
    position: absolute;
    top: 10px;
    left: calc((var(--ang) * 50%) + 50% - 30px);
    z-index: var(--ang-z);
    border-radius: 100%;
    padding: 30px;
    animation: earthBg linear infinite;
    animation-duration: 1s;
    animation-delay: calc((1s * var(--ang-full)) - 1.75s);
    animation-play-state: paused;
    pointer-events: none;
    
    &:before {
      content: '';
      position: absolute;
      inset: -15px 50%;
      width: 1px;
      transform: rotate(-23.4deg);
      border-left: 1px solid #fff8;
      z-index: 20;
    }
    
    &:after {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 50%;
      animation: earthFg linear infinite;
      animation-duration: inherit;
      animation-delay: inherit;
      animation-play-state: inherit;
    }
  }
  
  .sun {
    position: absolute;
    top: 0;
    z-index: 5;
    left: calc(50% - 40px);
    border-radius: 100%;
    background-color: #dbae2d;
    padding: 40px;
    pointer-events: none;
  }
  
  .labels {
    padding: 120px 0 40px;
    
    div {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      
      &:first-child {    
        span {
          display: inline-block;
          font-style: normal;
          border-bottom: 1px solid #fff8;
          padding: 0 3px;
          height: 16px;
        }
      }
      
      &:last-child {
        padding: 4px;
        font-size: 14px;
      }
    }
  }
}
              
            
!

JS

              
                let
  isHover = false,
  frame = 0;

const
  MAX_ANG = 23.4,
  MONTHS = ['December', 'January', 'Feburary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November'];

const
  label = document.getElementById('label'),
  northLabel = document.getElementById('northLabel'),
  southLabel = document.getElementById('southLabel'),
  angleCss = document.createElement('style');
document.head.prepend(angleCss);

function setAngle(angValue) {
  let ang = easeAng(angValue);
  angleCss.innerText =
    `body {
      --ang: ${ang};
      --ang-full: ${angValue};
      --ang-z: ${10 - Math.floor((angValue) * 10)};
    }`;
  
  label.innerHTML =
    Math.abs(ang * MAX_ANG).toFixed(1) +
    '&deg<br/>' +
    MONTHS[Math.floor(((angValue * 12) + 0.7) % 12)];
  
  const hrs = Math.round(7 + (5 * (1 + ang)));
  northLabel.innerText = hrs + ' hrs';
  southLabel.innerText = (24 - hrs) + ' hrs';
}

function easeAng(angValue) {
  let eased = (angValue > 0.5 ? 1 - angValue : angValue) * 2;
  eased = -0.5 * (Math.cos(Math.PI * eased) - 1);
  return (2 * eased) - 1;
}

function hoverOrbit(e) {
  frame = 125 * (e.offsetX / e.target.offsetWidth);
}

setInterval(() => {
  if (!isHover) {
    frame += 1;
    frame %= 250;
  }
  setAngle(frame / 250);
}, 50);
              
            
!
999px

Console