Custom Components
Countdown
Countdown
Instructions
Overview
Add a dynamic countdown timer to your website that displays the time remaining until a specific date and time.
Getting Started
Quick Start
- Click the Copy Component button on the top of the page.
- Paste the component into your Webstudio site.
Manual Start
- Add the Script: Copy and paste this code into your website's after the component:
[code-block]<script type="module" src="https://drevo.b-cdn.net/Library/Custom%20Components/Countdown/countdown-v1.0.js"></script>[/code-block]
- Add the Countdown Element: Place a container with the following attributes:
<div dv-countdown dv-countdown-target-date="2024-12-31" dv-countdown-target-time="23:59:59" dv-countdown-timezone="+00:00"></div>
. Inside this container, add an element withdv-countdown-display="true"
to contain all countdown units:<div dv-countdown-display="true"><!-- Units go here --></div>
Customization Options
Required Attributes
dv-countdown
= Main attribute to identify the countdown componentdv-countdown-target-date
= Target date in YYYY-MM-DD formatdv-countdown-target-time
= Target time in HH:MM:SS formatdv-countdown-timezone
= Timezone offset in +/-HH:MM format
Display Units
Add elements with the dv-countdown-unit
attribute to display specific time units:
dv-countdown-unit="years"
= Years remainingdv-countdown-unit="months"
= Months remainingdv-countdown-unit="days"
= Days remainingdv-countdown-unit="hours"
= Hours remainingdv-countdown-unit="minutes"
= Minutes remainingdv-countdown-unit="seconds"
= Seconds remaining
Example: <span dv-countdown-unit="days">00</span>
Completion Message
Add an element with dv-countdown-complete="true"
to display when countdown reaches zero:
<div dv-countdown-complete="true" style="display: none;">Countdown complete!</div>
Notes
- The countdown updates automatically every second
- When the countdown reaches zero, the display element is hidden and the complete element is shown
- You can include any combination of time units
- Time calculations adjust based on which units are displayed
- The component automatically reinitializes when added to the DOM dynamically