Learn why Gartner just named Builder a Cool Vendor

Announcing Visual Copilot - Figma to production in half the time

Builder.io logo
Contact Sales
Platform
Developers
Contact Sales

Blog

Home

Resources

Blog

Forum

Github

Login

Signup

×

Visual CMS

Drag-and-drop visual editor and headless CMS for any tech stack

Theme Studio for Shopify

Build and optimize your Shopify-hosted storefront, no coding required

Resources

Blog

Get StartedLogin

Popular Tutorials

>

Create a Countdown Timer Hero

Create a Countdown Timer Hero

This tutorial covers two options for adding a countdown hero to your project, one based solely in the Visual Editor that uses a built-in template, and for those who want more fine-grained control, a custom code option.

Skill set: Intermediate

Area: UI OR code

Video Length: 21 sec

  • You'll need a Builder account.
  • An evergreen browser; that is, a modern, up-to-date browser such as Google Chrome.

Use the Countdown featured template, as in the video:

  1. Go the Insert tab > Featured Templates
  2. Click View All Templates.
  3. Search for "countdown".
  4. Choose one of the countdown templates.

If you have access to code features, you can create a countdown with custom code. Note that we recommend that a developer finetune this example implementation.

In this example, the days text box is bound to state.days, the hours is bound to state.hours, the minutes are bound to state.minutes, and the seconds are bound to state.seconds.

  1. In the Visual Editor, add four text boxes, one for each number—days, hours, minutes, seconds—that will dynamically show the countdown values.
  2. In the Data tab > Code, click the Edit Content JS + CSS button. This opens the JavaScript and CSS editor for further customization.
  3. Within the Builder.isBrowser if statement, locate the existing code and update the finalDate variable to the Unix timestamp of the desired countdown end date. For example, to countdown to New Year's Day 2030, set finalDate to 1893456000000 (Unix timestamp of New Year's Day 2030).

The code should resemble this:

const second = 1000;
const minute = second * 60;
const hour = minute * 60;
const day = hour * 24;

state.days = "0";
state.hours = "0";
state.minutes = "0";
state.seconds = "0";

// New Year's Day 2030 - Unix time in milliseconds
let finalDate = 1893456000000;

const countDown = new Date(finalDate).getTime();
window.setInterval(myTimer, 1000);

function myTimer() {
   let now = new Date().getTime();
   let distance = countDown - now;
   state.days = Math.floor(distance / day);
   state.hours = Math.floor((distance % day) / hour);
   state.minutes = Math.floor((distance % hour) / minute);
   state.seconds = Math.floor((distance % minute) / second);
}

To get even more out of Templates with Builder, read Creating Templates.

Was this article helpful?

Product

Visual CMS

Theme Studio for Shopify

Sign up

Login

Featured Integrations

React

Angular

Next.js

Gatsby

Get In Touch

Chat With Us

Twitter

Linkedin

Careers

© 2020 Builder.io, Inc.

Security

Privacy Policy

Terms of Service

Newsletter

Get the latest from Builder.io

By submitting, you agree to our Privacy Policy

Product

Platform Overview

Integrations

What's New

Open Source

Builder

Builder

Mitosis

Mitosis

Qwik

Qwik

Partytown

Partytown

Popular Guides

From Design to Code Guide

Composable Commerce Guide

Headless CMS Guide

Headless Commerce Guide

Composable DXP Guide

Design to Code

Resources

Blog

Knowledge Base

Community Forum

Partners

Templates

Success Stories

Showcase

Resource Center

Frameworks

React

React

Next

Next.js

Qwik

Qwik

Gatsby

Gatsby

Angular

Angular

Vue

Vue

Svelte

Svelte

Remix logo

Remix

Nuxt

Nuxt

Hydrogen

Hydrogen

See All

© 2024 Builder.io, Inc.

Security

Privacy Policy

SaaS Terms

Security & Compliance

Cookie Preferences

Gartner Cool Vendor 2024