top of page

Wix Studio Tips and Tricks

Public·1 member

How to Create Countdown for Online Sales



<style>

  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap');

  body {

    font-family: 'Poppins', sans-serif;

    text-align: center;

  }

  #countdown {

    font-size: 16px;

    color: white; 

  }

</style>

<body>


<div id="countdown"></div>


<script>

  const endDate = new Date("August 14, 2024 23:59:59").getTime();


  const countdown = setInterval(() => {

    const now = new Date().getTime();


    const distance = endDate - now;

    const days = Math.floor(distance / (1000  60  60 * 24));

    const hours = Math.floor((distance % (1000  60  60  24)) / (1000  60 * 60));

    const minutes = Math.floor((distance % (1000  60  60)) / (1000 * 60));

    const seconds = Math.floor((distance % (1000 * 60)) / 1000);

    document.getElementById("countdown").innerHTML =

      days + " Days : " + hours + " Hours : " + minutes + " Minutes : " + seconds + " Seconds ";

    if (distance < 0) {

      clearInterval(countdown);

      document.getElementById("countdown").innerHTML = "SALE ENDED";

    }

  }, 1000);

</script>


</body>



372 Views
lee
Apr 20

Hi there! This code isn't working for me :( It doesn't read the same as the code you showed on your tutorial. I appreciate your any help you can provide. Thank you!

About

Share your cool Wix Studio Tips and Tricks

bottom of page