<digit-spinner>

A lightweight web component for odometer-style digit spinners.

API

<digit-spinner>

A digit spinner web component. Displays a numeric value as a sequence of animated digit elements.

Attributes

NameDescriptionTypeDefault
valueThe numeric value displayed by the spinner.number0
directionDetermines whether digits animate "forward” or "backward" or "shortest" path.Direction'forward'
durationThe duration of a single digit flip animation.number200
easingThe easing function to use for the digit transition.string'cubic-bezier(0.83, 0, 0.17, 1)'
min-digitsMinimum number of digit slots to render (pads with leading zeros). e.g. if value="195" and min-digits="5", you get 0, 0, 1, 9, 5.number0

Properties

NameAttributeDescriptionTypeDefault
valuevalueThe numeric value displayed by the spinner.number0
directiondirectionDetermines whether digits animate "forward” or "backward" or "shortest" path.Direction'forward'
durationdurationThe duration of a single digit flip animation.number200
easingeasingThe easing function to use for the digit transition.string'cubic-bezier(0.83, 0, 0.17, 1)'
minDigitsmin-digitsMinimum number of digit slots to render (pads with leading zeros). e.g. if value="195" and min-digits="5", you get 0, 0, 1, 9, 5.number0

Methods

NameParametersDescriptionReturn
increment
NameDescriptionType
numNumber of digits to incrementnumber
Increment the spinner value by `num`void
decrement
NameDescriptionType
numNumber of digits to decrementnumber
Decrement the spinner value by `num`void

Events

NameDescription
digit-flip-startFired when the digit flipping animation begins. The event has the following properties: * `from`: the digit value before the flip * `to`: the digit value after the flip
digit-flip-endFired when the digit flipping animation completes. The event has the following properties: * `from`: the digit value before the flip * `to`: the digit value after the flip
digit-wrapFired when the digit wraps forward from 9 to 0, or backward from 0 to 9. The event has the following properties: * `from`: the digit value before the wrap * `to`: the digit value after the wrap * `direction`: the direction of the wrap

CSS Shadow Parts

NameDescription
digitThe elements that represent an individual digit
digit-wrapperA wrapper element surrounding an individual digit
first-digitThe element representing the first digit
first-digit-wrapperThe wrapper element surrounding the first digit
last-digitThe element representing the last digit
last-digit-wrapperThe wrapper element surrounding the last digit

CSS Custom Properties

NameDescription
--spinner-backgroundThe background color of the spinner
--spinner-border-colorThe border color of the spinner
--spinner-border-widthThe border width of the spinner
--spinner-border-radiusThe border radius of the spinner
--spinner-font-familyThe font family of the spinner
--spinner-font-sizeThe font size of the spinner, also set by the `--digit-font-size` custom property
--spinner-paddingThe padding of the spinner
--digit-backgroundThe background color of the digit
--digit-border-radiusThe border radius of the digit
--digit-box-shadowThe box shadow of the digit
--digit-colorThe color of the digit
--digit-font-sizeThe font size of the digit, also set by the `--spinner-font-size` custom property
--digit-spacingThe spacing between digits
--digit-text-shadowThe text shadow of the digit, defaults to none

<spinning-digit>

A custom element that displays a single spinning digit. The digit can be animated to a new value. This element is intended for use in digit spinners, and is not intended for direct use.

Attributes

NameDescriptionTypeDefault
valueThe value of the digit. This value is updated immediately, and may not match the displayed value if the digit is animating.number0
directionThe direction of the digit transition. * If `forward`, the digit value will increase (e.g. from 9 to 0) until the target value is reached. * If `backward`, the digit value will decrease (e.g. from 0 to 9) until the target value is reached. * If `shortest`, the digit value will take the shortest path (either forward or backward) to the target value.Direction'forward'
durationThe duration of the digit transition in milliseconds.number200
easingThe easing function to use for the digit transition.string'cubic-bezier(0.83, 0, 0.17, 1)'

Properties

NameAttributeDescriptionTypeDefault
valuevalueThe value of the digit. This value is updated immediately, and may not match the displayed value if the digit is animating.number0
directiondirectionThe direction of the digit transition. * If `forward`, the digit value will increase (e.g. from 9 to 0) until the target value is reached. * If `backward`, the digit value will decrease (e.g. from 0 to 9) until the target value is reached. * If `shortest`, the digit value will take the shortest path (either forward or backward) to the target value.Direction'forward'
durationdurationThe duration of the digit transition in milliseconds.number200
easingeasingThe easing function to use for the digit transition.string'cubic-bezier(0.83, 0, 0.17, 1)'

Methods

NameParametersDescriptionReturn
increment
NameDescriptionType
numNumber of digits to incrementnumber
Increment the digit value by `num`void
decrement
NameDescriptionType
numNumber of digits to decrementnumber
Decrement the digit value by `num`void

Events

NameDescription
digit-flip-startFired when the digit flipping animation begins. The event has the following properties: * `from`: the digit value before the flip * `to`: the digit value after the flip
digit-flip-endFired when the digit flipping animation completes. The event has the following properties: * `from`: the digit value before the flip * `to`: the digit value after the flip
digit-wrapFired when the digit wraps forward from 9 to 0, or backward from 0 to 9. The event has the following properties: * `from`: the digit value before the wrap * `to`: the digit value after the wrap * `direction`: the direction of the wrap

CSS Shadow Parts

NameDescription
digit-wrapperThe wrapper element for the digits
digitThe digit element

CSS Custom Properties

NameDescription
--digit-backgroundThe background color of the digit
--digit-border-radiusThe border radius of the digit
--digit-box-shadowThe box shadow of the digit
--digit-colorThe color of the digit
--digit-font-sizeThe font size of the digit, also set by the `--spinner-font-size` custom property
--digit-text-shadowThe text shadow of the digit, defaults to none