Skip to content

Analog Clock

The Analog Clock component creates a stylish analog clock with customizable features including hour, minute, and second hands, day and month display, digital clock, and moon phase indicator.

See the Example by Serhii Pimenov on CodePen.

<!-- Basic usage -->
<div data-role="analog-clock"></div>
<!-- With custom options -->
<div data-role="analog-clock"
data-show-numbers="true"
data-show-moon="true"
data-time-format="12">
</div>
<!-- With custom icon -->
<div data-role="analog-clock"
data-icon="<span class='mif-rocket'>">
</div>
// Initialize analog clock on an existing element
Metro.makePlugin("#myClock", "analog-clock");
// Access the analog clock object
const clock = Metro.getPlugin("#myClock", "analog-clock");
ParameterTypeDefaultDescription
iconstringnullCustom icon to display on the clock (HTML content)
showNumbersbooleanfalseWhether to show numbers on the clock face instead of dashes
showMoonbooleantrueWhether to show the current moon phase
showDaybooleantrueWhether to show the day and month display
showDigitalClockbooleantrueWhether to show the digital clock
timeFormatnumber24Time format (12 or 24 hour)
onAnalogClockCreatefunctionMetro.noopCallback function triggered when the clock is created
EventDescription
onAnalogClockCreateTriggered when the analog clock is created
  • destroy() - Removes the analog clock component and its associated elements.
// Destroy the analog clock
const clock = Metro.getPlugin('#myClock', 'analog-clock');
clock.destroy();
VariableDefault (Light)Dark ModeDescription
--analog-clock-size300px300pxSize of the clock
--analog-clock-icon-size100px100pxSize of the icon
--analog-clock-border-color#6a6a6a#6a6a6aBorder color of the clock
--analog-clock-dash-color#191919#efefefColor of the hour markers
--analog-clock-backgroundvar(—default-background)var(—default-background)Background color of the clock
--analog-clock-colorvar(—default-color)var(—default-color)Text color
--analog-clock-hour-colorvar(—color-dark)#cdcdcdHour hand color
--analog-clock-minute-colorvar(—color-dark)#cdcdcdMinute hand color
--analog-clock-second-colorvar(—color-red)var(—color-red)Second hand color
--analog-clock-hand-border-color#ccc#efefefBorder color of the hands
--analog-clock-inset-border-color#e6e6e6#333333Inset border color
--analog-clock-inset-shadowrgba(0,0,0,0.45)#919191Inset shadow color
/* Custom styling for a specific analog clock */
#myCustomClock {
--analog-clock-size: 400px;
--analog-clock-hour-color: #2196F3;
--analog-clock-minute-color: #2196F3;
--analog-clock-second-color: #FF5722;
}
  • .analog-clock - The main container class for the analog clock
  • .show-numbers - Added when numbers are displayed instead of dashes
  • .size-xs - Extra small size
  • .size-sm - Small size
  • .size-md - Medium size
  • .size-lg - Large size
  • .size-xl - Extra large size

The Analog Clock component:

  • Automatically updates the time every second
  • Displays the current day, month, and day of the week when enabled
  • Shows the current moon phase when enabled (new-moon, waxing-crescent, first-quarter, etc.)
  • Has a “tick” animation that toggles every 500ms
  • Adapts to both light and dark themes
  • Can display both analog and digital time simultaneously