Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="radial">
  <div class="radial__track">
  </div>
  <div class="radial__indicators">
    <div class="radial__indicator">
      <svg viewBox="0 0 640 512"  title="cloud-sun">
        <path d="M575.2 325.7c.2-1.9.8-3.7.8-5.6 0-35.3-28.7-64-64-64-12.6 0-24.2 3.8-34.1 10-17.6-38.8-56.5-66-101.9-66-61.8 0-112 50.1-112 112 0 3 .7 5.8.9 8.7-49.6 3.7-88.9 44.7-88.9 95.3 0 53 43 96 96 96h272c53 0 96-43 96-96 0-42.1-27.2-77.4-64.8-90.4zm-430.4-22.6c-43.7-43.7-43.7-114.7 0-158.3 43.7-43.7 114.7-43.7 158.4 0 9.7 9.7 16.9 20.9 22.3 32.7 9.8-3.7 20.1-6 30.7-7.5L386 81.1c4-11.9-7.3-23.1-19.2-19.2L279 91.2 237.5 8.4C232-2.8 216-2.8 210.4 8.4L169 91.2 81.1 61.9C69.3 58 58 69.3 61.9 81.1l29.3 87.8-82.8 41.5c-11.2 5.6-11.2 21.5 0 27.1l82.8 41.4-29.3 87.8c-4 11.9 7.3 23.1 19.2 19.2l76.1-25.3c6.1-12.4 14-23.7 23.6-33.5-13.1-5.4-25.4-13.4-36-24zm-4.8-79.2c0 40.8 29.3 74.8 67.9 82.3 8-4.7 16.3-8.8 25.2-11.7 5.4-44.3 31-82.5 67.4-105C287.3 160.4 258 140 224 140c-46.3 0-84 37.6-84 83.9z" />
      </svg>
    </div>
    <div class="radial__indicator">
      <svg viewBox="0 0 576 512" title="cloud-moon">
        <path d="M342.8 352.7c5.7-9.6 9.2-20.7 9.2-32.7 0-35.3-28.7-64-64-64-17.2 0-32.8 6.9-44.3 17.9-16.3-29.6-47.5-49.9-83.7-49.9-53 0-96 43-96 96 0 2 .5 3.8.6 5.7C27.1 338.8 0 374.1 0 416c0 53 43 96 96 96h240c44.2 0 80-35.8 80-80 0-41.9-32.3-75.8-73.2-79.3zm222.5-54.3c-93.1 17.7-178.5-53.7-178.5-147.7 0-54.2 29-104 76.1-130.8 7.3-4.1 5.4-15.1-2.8-16.7C448.4 1.1 436.7 0 425 0 319.1 0 233.1 85.9 233.1 192c0 8.5.7 16.8 1.8 25 5.9 4.3 11.6 8.9 16.7 14.2 11.4-4.7 23.7-7.2 36.4-7.2 52.9 0 96 43.1 96 96 0 3.6-.2 7.2-.6 10.7 23.6 10.8 42.4 29.5 53.5 52.6 54.4-3.4 103.7-29.3 137.1-70.4 5.3-6.5-.5-16.1-8.7-14.5z" />
      </svg>
    </div>

  </div>
  <div class="radial__ring">
    <button class="radial__handle">
      <svg viewBox="0 0 512 512" title="sun">
        <path d="M256 160c-52.9 0-96 43.1-96 96s43.1 96 96 96 96-43.1 96-96-43.1-96-96-96zm246.4 80.5l-94.7-47.3 33.5-100.4c4.5-13.6-8.4-26.5-21.9-21.9l-100.4 33.5-47.4-94.8c-6.4-12.8-24.6-12.8-31 0l-47.3 94.7L92.7 70.8c-13.6-4.5-26.5 8.4-21.9 21.9l33.5 100.4-94.7 47.4c-12.8 6.4-12.8 24.6 0 31l94.7 47.3-33.5 100.5c-4.5 13.6 8.4 26.5 21.9 21.9l100.4-33.5 47.3 94.7c6.4 12.8 24.6 12.8 31 0l47.3-94.7 100.4 33.5c13.6 4.5 26.5-8.4 21.9-21.9l-33.5-100.4 94.7-47.3c13-6.5 13-24.7.2-31.1zm-155.9 106c-49.9 49.9-131.1 49.9-181 0-49.9-49.9-49.9-131.1 0-181 49.9-49.9 131.1-49.9 181 0 49.9 49.9 49.9 131.1 0 181z" />
      </svg>
      <svg viewBox="0 0 512 512" title="moon">
        <path d="M283.211 512c78.962 0 151.079-35.925 198.857-94.792 7.068-8.708-.639-21.43-11.562-19.35-124.203 23.654-238.262-71.576-238.262-196.954 0-72.222 38.662-138.635 101.498-174.394 9.686-5.512 7.25-20.197-3.756-22.23A258.156 258.156 0 0 0 283.211 0c-141.309 0-256 114.511-256 256 0 141.309 114.511 256 256 256z" />
      </svg>
    </button>
  </div>
  <h2 class="radial__time"></h2>
  <input class="sr-only" type="range" id="radial" min="0" max="1440" value="0" step="1">
</div>
              
            
!

CSS

              
                @import "https://unpkg.com/open-props/open-props.min.css";
@import "https://unpkg.com/open-props/normalize.min.css";

*,
*:after,
*:before {
  box-sizing: border-box;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-family: "Google Sans", sans-serif, system-ui;
  transition: background 0.25s;
}

.radial {
  --border-width: 12px;
  --diameter: clamp(200px, 30vmin, 28rem);
  --handle-size: 48px;
  width: var(--diameter);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
}

.radial__ring {
  position: absolute;
  height: 100%;
  width: 100%;
}

.radial__handle {
  width: var(--handle-size);
  aspect-ratio: 1;
  border-radius: 50%;
  position: absolute;
  left: 50%;
  bottom: calc(100% - (var(--border-width) * 0.5));
  transform: translate(-50%, 50%);
  box-shadow: var(--shadow-6);
  padding: 0;
  border: 2px solid hsl(0 0% 85%);
  background: var(--gray-0);
  display: grid;
  place-items: center;
}

.radial__handle svg {
  width: 70%;
  aspect-ratio: 1;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: background 0.25s;
}

.radial__handle [title=sun] {
  fill: var(--yellow-4);
}

.radial__handle [title=moon] {
  width: 45%;
  fill: var(--gray-4);
  transform: translate(-50%, -50%) scale(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.radial__track {
  height: 100%;
  width: 100%;
  position: absolute;
  background:
    conic-gradient(from 270deg, var(--yellow-4) calc(var(--sun-stop, 0) * 1%), transparent calc(var(--sun-stop, 0) * 1%)),
    conic-gradient(from 90deg, var(--gray-7) calc(var(--moon-stop, 0) * 1%), transparent calc(var(--moon-stop, 0) * 1%)),
    var(--surface-2);
  border-radius: 50%;
  --stop: calc(var(--diameter) * 0.5 - var(--border-width));
  mask: radial-gradient(transparent var(--stop), black var(--stop));
}

.radial__indicators {
  height: 100%;
  width: 100%;
  position: absolute;
}

.radial__indicator {
  width: 48px;
  aspect-ratio: 1;
  position: absolute;
  background: var(--gray-0);
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 2px solid var(--gray-4);
}

.radial__indicator:first-of-type {
  --fill: var(--yellow-4);
  top: 50%;
  right: 100%;
  transform: translate(calc(50% + (var(--border-width) * 0.5)), -50%);
}

.radial__indicator:last-of-type {
  --fill: var(--gray-4);
  top: 50%;
  left: 100%;
  transform: translate(calc(-50% - (var(--border-width) * 0.5)), -50%);
}

.radial__indicator svg {
  fill: var(--fill);
  width: 55%;
}

.radial__time {
  transition: color 0.25s;
  font-variant: tabular-nums;
}

.radial__track circle {
  stroke-width: 12px;
  stroke: red;
}
              
            
!

JS

              
                const INPUT = document.querySelector('[type=range]')

const ROTATE_MAPPER = gsap.utils.mapRange(0, INPUT.max, 0, 360)
const PROGRESS_MAPPER = gsap.utils.mapRange(0, INPUT.max * 0.5, 0, 50)

gsap.registerPlugin(Draggable)

gsap.set('[title="moon"]', { scale: 0 })

const minToTime = minutes => `${`${Math.floor(minutes/60)}`.padStart(2, '0')}:${`${Math.floor(minutes%60)}`.padStart(2, '0')}`


const SUNRISE = 465
const SUNSET = 465 + (12 * 60)
// let rotationSnap = 360 / 24
let rotationSnap = 15

const onInput = function() {
  if (this.rotation) {
    let VALUE = Math.floor(((this.rotation % 360) / 360) * INPUT.max)
    if (VALUE < 0) VALUE = INPUT.max - Math.abs(VALUE)
    INPUT.value = VALUE
  } else {
    gsap.set('.radial__ring', {
      rotate: ROTATE_MAPPER(INPUT.value)
    }) 
  }
  const TIME = minToTime(gsap.utils.wrap(0, 1440, parseInt(INPUT.value, 10) + (SUNSET + (SUNRISE - SUNSET) * 0.5)))
  gsap.set('.radial__time', {
    innerText: TIME
  })
  gsap.set('.radial__handle', {
    rotate: ROTATE_MAPPER(-INPUT.value)
  })
  if (INPUT.value > INPUT.max * 0.25 && INPUT.value < INPUT.max * 0.75) {
    gsap.to('[title="sun"]', { scale: 0, duration: 0.25 })
    gsap.to('[title="moon"]', { scale: 1, duration: 0.25 })
    gsap.set('.radial__handle', { background: 'var(--gray-8)' })
    gsap.set('body', { background: 'var(--text-1)'})
    gsap.set('.radial__time', { color: 'var(--surface-1)'})
  } else {
    gsap.to('[title="moon"]', { scale: 0, duration: 0.25 })
    gsap.to('[title="sun"]', { scale: 1, duration: 0.25 })
    gsap.set('.radial__handle', { background: 'var(--gray-0)' })
    gsap.set('body', { background: 'var(--surface-1)' })
    gsap.set('.radial__time', { color: 'var(--text-1)' })
  }
  // Based on the value work out the conic-gradient percentages...
  // Remember the ring starts at 0 and the input at 0 but the stops are offset.
  const sunInput = INPUT.value > INPUT.max * 0.75 ? parseInt(INPUT.value, 10) - INPUT.max * 0.75 : parseInt(INPUT.value, 10) + INPUT.max * 0.25
  const moonInput = INPUT.value > INPUT.max * 0.75 ? 0 : INPUT.value - INPUT.max * 0.25
  gsap.set('.radial__track', {
    '--sun-stop': gsap.utils.clamp(0, 50, PROGRESS_MAPPER(sunInput)),
    '--moon-stop': gsap.utils.clamp(0, 50, PROGRESS_MAPPER(moonInput))
  })
}

window.__RADIAL = Draggable.create(".radial__ring", {
  trigger: '.radial__handle',
  type:"rotation",
  inertia: true,
  onThrowUpdate: onInput,
  onDrag: onInput,
  snap:function(endValue) {
    return Math.round(endValue / rotationSnap) * rotationSnap;
  }
});

INPUT.addEventListener('input', onInput)

onInput()
              
            
!
999px

Console