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="egg-container">
  <div class="egg">
    - const faceCount = 48
    .egg-top(style=`--face-count: ${faceCount}`)
      .time-ruler-faces-container
        - for (let i = 0; i < faceCount; i++)
          .time-ruler-face-wrapper(style=`--i: ${i}`)
            svg.time-ruler-face(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1740 76", aria-hidden="true")
              use(href="#time-ruler")
    <div class="egg-center"></div>
    <div class="egg-bottom">
      <div class="time-arrow"></div>
      <p class="time-container">0:00</p>
    </div>
  </div>
  <button class="timer-button" type="button" disabled>Start</button>
</div>

<svg viewBox="0 0 1740 76" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" style="position: absolute; width: 0; height: 0;">
  <defs>
    <symbol id="time-ruler">
      <path d="M-8 46H8v30H-8zm145 0h16v30h-16zM27 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM172 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM317 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM462 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM607 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM752 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zM897 66h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zm-110 20h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zm-110 20h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zm-110 20h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zm-110 20h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm168-20h16v30h-16zm-110 20h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4zm29 0h4v10h-4z"/>
      <use href="#E" x="-118.3"/>
      <use href="#E" x="-408.3"/>
      <use href="#E" x="171.7"/>
      <use href="#B"/>
      <use href="#C"/>
      <use href="#D"/>
      <use href="#C" x="145"/>
      <use href="#E"/>
      <use href="#D" x="290"/>
      <use href="#E" x="145"/>
      <use href="#E" x="448.35"/>
      <use href="#F"/>
      <use href="#D" x="870"/>
      <use href="#F" x="145"/>
      <use href="#E" x="751.7"/>
      <use href="#G"/>
      <use href="#D" x="1160"/>
      <use href="#G" x="145"/>
      <use href="#E" x="1041.7"/>
      <use href="#B" x="1595"/>
      <use href="#D" x="566.653"/>
      <use href="#D" x="-290"/>
      <defs>
        <path id="B" d="M127.753 7.776c-.75 1-1.109 2.336-1.078 4.008h-6.234c.063-1.687.352-3.289.867-4.805.547-1.328 1.406-2.555 2.578-3.68.875-.797 1.914-1.406 3.117-1.828s2.68-.633 4.43-.633c3.25 0 5.871.84 7.863 2.52s2.988 3.934 2.988 6.762c0 2-.594 3.688-1.781 5.063-.75.859-1.531 1.445-2.344 1.758.609 0 1.484.523 2.625 1.57 1.703 1.578 2.555 3.734 2.555 6.469 0 2.875-.996 5.402-2.988 7.582s-4.941 3.27-8.848 3.27c-4.812 0-8.156-1.57-10.031-4.711-.984-1.672-1.531-3.859-1.641-6.562h6.563c0 1.359.219 2.484.656 3.375.813 1.641 2.289 2.461 4.43 2.461 1.313 0 2.457-.449 3.434-1.348s1.465-2.191 1.465-3.879c0-2.234-.906-3.727-2.719-4.477-1.031-.422-2.656-.633-4.875-.633v-4.781c2.172-.031 3.688-.242 4.547-.633 1.484-.656 2.227-1.984 2.227-3.984 0-1.297-.379-2.352-1.137-3.164s-1.824-1.219-3.199-1.219c-1.578 0-2.734.5-3.469 1.5z"/>
        <path id="C" d="M288.667 22.448v5.227h-3.844v7.312h-6.539v-7.312h-13.453v-5.836l12.492-20.625h7.5v21.234h3.844zm-18.891 0h8.508V7.776l-8.508 14.672z"/>
        <path id="D" d="M303.48 35.831c-4.328 0-7.363-1.516-9.105-4.547s-2.613-7.352-2.613-12.961.871-9.937 2.613-12.984 4.777-4.57 9.105-4.57 7.367 1.523 9.117 4.57c1.734 3.047 2.602 7.375 2.602 12.984s-.871 9.93-2.613 12.961-4.777 4.547-9.105 4.547zm3.914-8.555c.609-2.062.914-5.047.914-8.953 0-4.094-.309-7.125-.926-9.094s-1.918-2.953-3.902-2.953-3.297.984-3.937 2.953-.961 5-.961 9.094c0 3.906.32 6.895.961 8.965s1.953 3.105 3.938 3.105 3.289-1.039 3.914-3.117z"/>
        <path id="E" d="M566.363 18.112c-.812 0-1.516.102-2.109.305-1.047.375-1.836 1.07-2.367 2.086l-6-.281 2.391-18.773h18.727V7.12h-13.898l-1.219 7.43c1.031-.672 1.836-1.117 2.414-1.336.969-.359 2.148-.539 3.539-.539 2.813 0 5.266.945 7.359 2.836s3.141 4.641 3.141 8.25c0 3.141-1.008 5.945-3.023 8.414s-5.031 3.703-9.047 3.703c-3.234 0-5.891-.867-7.969-2.602s-3.234-4.195-3.469-7.383h6.656c.266 1.453.773 2.574 1.523 3.363s1.844 1.184 3.281 1.184c1.656 0 2.918-.582 3.785-1.746s1.301-2.629 1.301-4.395c0-1.734-.406-3.199-1.219-4.395s-2.078-1.793-3.797-1.793z"/>
        <path id="F" d="M1151.73 34.987h-6.844V11.55h-7.992V7.003c2.109-.094 3.586-.234 4.43-.422 1.344-.297 2.438-.891 3.281-1.781.578-.609 1.016-1.422 1.313-2.437.172-.609.258-1.062.258-1.359h5.555v33.984z"/>
        <path id="G" d="M1440.254 7.917c-.797-.953-1.937-1.43-3.422-1.43-2.031 0-3.414.758-4.148 2.273-.422.875-.672 2.266-.75 4.172h-6.492c.109-2.891.633-5.227 1.57-7.008 1.781-3.391 4.945-5.086 9.492-5.086 3.594 0 6.453.996 8.578 2.988s3.188 4.629 3.188 7.91c0 2.516-.75 4.75-2.25 6.703-.984 1.297-2.602 2.742-4.852 4.336l-2.672 1.898c-1.672 1.188-2.816 2.047-3.434 2.578s-1.137 1.148-1.559 1.852h14.836v5.883h-23.273c.063-2.437.586-4.664 1.57-6.68.953-2.266 3.203-4.664 6.75-7.195 3.078-2.203 5.07-3.781 5.977-4.734 1.391-1.484 2.086-3.109 2.086-4.875 0-1.437-.398-2.633-1.195-3.586z"/>
      </defs>
    </symbol>
  </defs>
</svg>

              
            
!

CSS

              
                @import 'compass/css3';

$face-count: 48;

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1em;
  min-height: 100vh;
  font-family: 'Helvetica', sans-serif;
  font-weight: 500;
  font-feature-settings: 'tnum';
  font-variant-numeric: tabular-nums;
}

.egg-container {
  transform: scale(.25);
  transition: transform .2s;
  
  &.active {
    transform: scale(1);
  }
}

.egg {
  --shadow-opacity: 1;
  border-radius: 100% 100% 76% 76% / 118% 118% 80% 80%;
  filter: drop-shadow(0 0px 2px Rgb(0 0 0 / var(--shadow-opacity)));
  cursor: pointer;

  .egg-container.active & {
    --shadow-opacity: 0;
    cursor: initial;
  }
  
  &.ringing {
    animation: ring .12s infinite;
  }
}

@keyframes ring {
  0%,
  50%,
  100% { 
    transform: rotate(0);
  }
  25% {
    transform: rotate(5deg);
  }
  75% {
    transform: rotate(-5deg);
  }
}

@mixin egg-background {
  background-color: #f4f4f4;
  background-image:
    url('https://assets.codepen.io/4175254/final-2.png'),
    linear-gradient(to right, #e6e6e6, #fff, #e6e6e6),
  ;
  background-size: 60px 60px, auto auto;
  background-blend-mode: multiply, normal;
}

.egg-top {
  $border-radius: 50% 50% 50% 50% / 100% 100% 0% 0%;
  @include egg-background;
  --background-translation: 0px;
  position: relative;
  z-index: 1;
  border-radius: $border-radius;
  width: 274px;
  height: 210px;
  //mask-image: radial-gradient(#fff, #fff);
  clip-path: inset(0 0 0 0 round $border-radius);
  background-position-x: var(--background-translation), 0%;
  box-shadow:
    inset 0 4px 8px Rgb(0 0 0 / .05),
    inset 20px 0 16px Rgb(0 0 0 / .05),
    inset -20px 0 16px Rgb(0 0 0 / .05),
    inset 0 1px 1px Rgb(0 0 0 / .05),
    inset 1px 0 1px Rgb(0 0 0 / .05),
    inset -1px 0 1px Rgb(0 0 0 / .05),
  ;
  transition: background-position-x .2s;
  touch-action: none;
  
  &.dragged {
    transition-duration: 0s;
    transition-timing-function: ease-out;
  }
  
  .egg-container.active .egg:not(.ringing) & {
    cursor: ew-resize;
  }
}

.time-ruler-faces-container {
  --initial-rotation: calc(180deg + (360deg / var(--face-count) / 2));
  --rotation: 0deg;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  bottom: 6px;
  transform: rotateY(calc(var(--rotation) + var(--initial-rotation)));
  transform-style: preserve-3d;
  aspect-ratio: #{1740 / pi()} / 76;
  width: 100%;
  transition: transform .4s;
  
  .egg-top.dragged & {
    transition-duration: 0s;
    transition-timing-function: ease-out;
  }
}

.time-ruler-face-wrapper {
  // background-color: red;
  $anti-gap-shift: 3px;
  --angle: calc(360deg / var(--face-count) * var(--i));
  position: absolute;
  // transform: rotateY(calc(var(--angle) - 90deg)) translateX(calc(100% * var(--face-count) / #{pi()} / 2 - #{$anti-gap-shift})) rotateY(90deg);
  transform: rotateY(calc(var(--angle) - 90deg)) translateX(calc(100% / (2 * #{tan(pi() / $face-count)}) - #{$anti-gap-shift})) rotateY(90deg);
  backface-visibility: hidden;
  // width: calc(100% * #{pi()} / var(--face-count));
  width: calc(100% * #{sin(pi() / $face-count)});
  height: 100%;
  overflow: hidden;
}

.time-ruler-face {
  position: absolute;
  top: 0;
  left: calc(-100% * var(--i));
  height: 100%;
  fill: #484848;
  will-change: transform;
}

.egg-center {
  margin: 0 auto;
  height: 6px;
  width: calc(100% - 24px);
  background-color: #f4f4f4;
  box-shadow: 
    inset 0 6px 2px Rgb(0 0 0 / .2),
    inset 0 2px 2px Rgb(0 0 0 / .2);
  ;
}

.egg-bottom {
  @include egg-background;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 0% 0% 38% 38% / 0% 0% 100% 100%;
  width: 274px;
  height: 144px;
  box-shadow:
    inset 0 1px 0 Rgb(255 255 255 / .8),
    inset 0 -1px 1px Rgb(0 0 0 / .05),
    inset 1px 0 1px Rgb(0 0 0 / .05),
    inset -1px 0 1px Rgb(0 0 0 / .05),
    inset 0 -12px 8px Rgb(255 255 255 / .6),
    inset 0 -20px 8px Rgb(0 0 0 / .1),
    inset 0 -60px 20px Rgb(0 0 0 / .05),
  ;
}

.time-arrow {
  $width: 20px;
  $height: 14px;
  position: relative;
  z-index: 1;
  margin-top: 8px;
  margin-bottom: -1px; // remove weird Chrome gap;
/*  border-bottom: $height solid #d15705;
  border-right: $width / 2 solid transparent;
  border-left: $width / 2 solid transparent;
  width: 0;
  height: 0;*/
  width: $width;
  height: $height;
  background-color: #d15705;
  clip-path: polygon(50% 0, 0% 100%, 100% 100%);
}

.time-container {
  border-radius: 10px;
  padding: 4px 16px;
  transform: scale(.125, 0);
  transform-origin: top;
  background-color: #d15705;
  box-shadow: 
    inset 0 -2px Rgb(0 0 0 / .2),
    0 2px 4px Rgb(0 0 0 / .2),
  ;
  font-size: 32px;
  color: #f4f4f4;
  transition: transform .2s;
  
  .egg-container.active & {
    transform: scale(1);
    transition-duration: .2s;
    transition-timing-function: cubic-bezier(0, 0, .3, 1.5);
    transition-delay: .1s;
  }
}

.timer-button {
  margin-top: 1.5em;
  border-radius: 8px;
  padding: 10px 16px;
  transform: scale(0);
  width: 100%;
  background-image: linear-gradient(to bottom, #84b709, #46a100);
  box-shadow: 
    inset 0 -2px Rgb(0 0 0 / .2),
    0 2px 4px Rgb(0 0 0 / .2),
  ;
  text-align: center;
  font-weight: 600;
  color: #fff;
  opacity: 0;
  transition-property: transform, opacity;
  transition-duration: .4s, .2s;
  transition-timing-function: cubic-bezier(.55, 1, .15, 1), ease-in-out;
  
  .egg-container.active & {
    transform: scale(1);
    opacity: 1;
  }
  
  &.stop {
    background-image: linear-gradient(to bottom, #d53f0b, #b00000);
  }
  
  &:active:not(:disabled) {
    transform: scale(.92);
  }
  
  &:disabled {
    background-image: linear-gradient(to bottom, #9f9f9f, #848484);
    cursor: not-allowed;
    
    .egg-container.active & {
      opacity: .4;
    }
  }
}

              
            
!

JS

              
                // to do:
// Element.setPointerCapture()
// Element.releasePointerCapture()
// https://developer.mozilla.org/fr/docs/Web/API/Element/setPointerCapture

const eggContainer = document.querySelector('.egg-container');
const egg = document.querySelector('.egg');
const eggTop = document.querySelector('.egg-top');
const timeRuler = document.querySelector('.time-ruler-faces-container');
const timeContainer = document.querySelector('.time-container');
const timerButton = document.querySelector('.timer-button');
const minuteDegreeInterval = 6;
const secondDegreeInterval = minuteDegreeInterval / 60;
let timerInterval;

const timerWindingSound = new Howl({
  src: ['https://assets.codepen.io/4175254/timer-winding_1.mp3'],
});

const timerAlarmSound = new Howl({
  src: ['https://assets.codepen.io/4175254/timer-alarm.mp3'],
});

const timerTickingSound = new Howl({
  src: ['https://assets.codepen.io/4175254/timer-ticking.mp3'],
  loop: true,
});

const closeTimer = () => {
  eggContainer.classList.remove('active');
  eggContainer.addEventListener('click', openTimer);
  document.removeEventListener('click', closeTimer);
};

const handleClickOutside = (e) => {
  if (!e.target.closest('.egg, .timer-button') && !timerAlarmSound.playing()) {
    document.addEventListener('pointerup', (e) => {
      if (!e.target.closest('.egg, .timer-button')) {
        eggContainer.classList.remove('active');
        document.removeEventListener('pointerdown', handleClickOutside);
      }
    }, { once: true });
  }
};

const isTimerOpen = () => eggContainer.classList.contains('active');

const openTimer = (e) => {
  e.stopPropagation();
  if (isTimerOpen() || timerAlarmSound.playing()) return;
  eggContainer.classList.add('active');
  document.addEventListener('pointerdown', handleClickOutside);
};

egg.addEventListener('click', openTimer);

const isTimerRunning = () => !!timerInterval;

const pauseTimer = () => {
  timerTickingSound.pause();
  clearInterval(timerInterval);
};

const stopTimer = () => {
  pauseTimer();
  timerInterval = null;
  timerButton.textContent = 'Start';
  timerButton.classList.remove('stop');
};

const resumeTimer = () => {
  timerTickingSound.play();
  timerInterval = setInterval(() => {
    const currentRotation = getTimeRulerRotation();
    if ((currentRotation + secondDegreeInterval) >= 0) {
      egg.classList.add('ringing');
      updateTime(0);
      stopTimer();
      
      timerAlarmSound.once('end', () => {
        egg.classList.remove('ringing');
      });
      
      timerAlarmSound.play();
      navigator.vibrate?.(timerAlarmSound.duration() * 1000);
      timerButton.disabled = true;
      
      return;
    };
    const newRotation = currentRotation + secondDegreeInterval;
    timeRuler.style.setProperty('--rotation', `${newRotation}deg`);
    const translation = parseFloat(getComputedStyle(eggTop).getPropertyValue('--background-translation'));
    const newTranslation = translation + (12 / 10);
    eggTop.style.setProperty('--background-translation', `${newTranslation}px`);
    updateTime(newRotation);
  }, 1000);
};

const startTimer = () => {
  resumeTimer();
  timerButton.textContent = 'Stop';
  timerButton.classList.add('stop');
};

const getTimeRulerRotation = () => {
  return parseFloat(getComputedStyle(timeRuler).getPropertyValue('--rotation'));
};

const getAdjustedTimeRulerRotation = (timeRulerRotation = getTimeRulerRotation()) => { 
  const minRotation = -360;
  const maxRotation = 0;
  const adjustedRotation = Math.max(minRotation, Math.min(maxRotation, Math.round(timeRulerRotation / minuteDegreeInterval) * minuteDegreeInterval));
  return adjustedRotation;
};

const adjustTimeRulerRotation = () => {
  timeRuler.style.setProperty('--rotation', `${getAdjustedTimeRulerRotation()}deg`);
};

const updateTime = (rotation) => {
  const totalSeconds = Math.round(Math.abs(rotation / secondDegreeInterval));
  const hours = Math.floor(totalSeconds / 3600);
  const minutes = Math.floor((totalSeconds % 3600) / 60);
  const seconds = Math.floor(totalSeconds % 60);
  const formattedMinutes = String(minutes).padStart(2, '0');
  const formattedSeconds = String(seconds).padStart(2, '0');
  timeContainer.textContent = hours ? `${hours}:${formattedMinutes}:${formattedSeconds}` : `${minutes}:${formattedSeconds}`;
};

let lastRotation = 0;

eggTop.addEventListener('pointerdown', (e) => {
  e.preventDefault();
  if (!isTimerOpen() || timerAlarmSound.playing()) return;
  const startX = e.clientX;
  const startAngle = getTimeRulerRotation();
  eggTop.classList.add('dragged');
  if (isTimerRunning()) pauseTimer();
  
  const pointerMoveHandler = (e) => {
    e.preventDefault();
    const deltaX = e.clientX - startX;
    const angle = deltaX / 2;
    const endAngle = startAngle + angle;
    timeRuler.style.setProperty('--rotation', `${endAngle}deg`);
    const adjustedRotation = getAdjustedTimeRulerRotation(endAngle);
    eggTop.style.setProperty('--background-translation', `${deltaX}px`);
    updateTime(adjustedRotation);
    
    if (!isTimerRunning()) {    
      timerButton.disabled = adjustedRotation >= 0;
    }
    
    if (Math.abs(adjustedRotation - lastRotation) >= 6) {
      timerWindingSound.play();
      navigator.vibrate?.(50);
      lastRotation = adjustedRotation;
    }
  };

  const pointerUpHandler = () => {
    eggTop.classList.remove('dragged');
    if (isTimerRunning()) resumeTimer();
    adjustTimeRulerRotation();
    const translation = parseFloat(getComputedStyle(eggTop).getPropertyValue('--background-translation'));
    const adjustedTranslation = Math.max(0, Math.min(-720, Math.round(translation / 12) * 12));
    eggTop.style.setProperty('--background-translation', `${adjustedTranslation}px`);
    document.removeEventListener('pointermove', pointerMoveHandler);
    document.removeEventListener('pointerup', pointerUpHandler);
  };

  document.addEventListener('pointermove', pointerMoveHandler);
  document.addEventListener('pointerup', pointerUpHandler);
});

timerButton.addEventListener('click', () => {
  isTimerRunning() ? stopTimer() : startTimer();
});

              
            
!
999px

Console