JavaScript timer to achieve limited time flash sale function

JavaScript timer to achieve limited time flash sale function

This article shares the specific code of JavaScript to implement the limited-time flash sale function for your reference. The specific content is as follows

File index.html

Code:

<!DOCTYPE html>
<html>
 <head>
  <meta charset="GBK" />
  <title>show</title>
  <link rel="stylesheet" href="css/index.css" type="text/css" />
  
 </head>
 <body>
  
  <div class="divMain">
   <img src="img/secondBuyImg.jpg" id="imgMain" />
   <h3 style="color: #FF0000;">The remaining time until the flash sale ends is:</h3>
   <div id="divSecond">
    
    <div id="divF1" class="divFours">
     <font class="fontdate" size="4" id="font1">00</font>
     <font class="fonttext" size="4">day</font>
    </div>
    <div id="divF2" class="divFours">
     <font class="fontdate" size="4" id="font2">00</font>
     <font class="fonttext" size="4">Time</font>
    </div>
    <div id="divF3" class="divFours">
     <font class="fontdate" size="4" id="font3">00</font>
     <font class="fonttext" size="4">Minutes</font>
    </div>
    <div id="divF4" class="divFours">
     <font class="fontdate" size="4" id="font4">00</font>
     <font class="fonttext" size="4">Seconds</font>
    </div>
   </div>
  </div>
  
 </body>
</html>
<script type="text/javascript" src="js/index.js"></script>

Style sheet file index.css

#imgMain{
 
}
.divMain{/*outer div*/
width: 100%;
height: 100%;
 display: flex;
 justify-content: left;
 align-items: center;/*located at the vertical center of the elastic box*/
 flex-direction: column;/*Set the sorting direction of the flexible box*/
}
/* Outer time div */
#divSecond{
 width: 500px;
 height: 500px;
 display: flex;
 justify-content: center;
 align-items:flex-start;
 flex-direction: row;
}
.divFours{/*time div1-4*/
 width: 10%;
 height: 10%;
 border: 2px solid red;
 display: flex;
 flex-direction: row;
 justify-content: center;
 align-items: center;
}
/* Image outer div */
#divFrist{
 width: 20%;
}
/* Remaining time display */
.fontdate{
 color: deeppink;
}
.fonttext{
 color: darkblue;
}

JavaScript file index.js

function torun(str){
 
 var date = new Date();
 var systemDay=date.getDate();
 var systemHour=date.getHours();
 var systemMinute=date.getMinutes();
 var systemSecond=date.getSeconds();
 
 var endDate = new Date(str);
 var endDay=endDate.getDate();
 var endHour=endDate.getHours();
 var endMinute=endDate.getMinutes();
 var endSecond=endDate.getSeconds();
 
 var remainingDay=-(systemDay-endDay)-1;
 var remainingHour=-(systemHour-endHour)-1;
 var remainingMinute=-(systemMinute-endMinute)-1;
 var remainingSecond=(systemSecond-endSecond>=0)?systemSecond-endSecond+59:-(systemSecond-endSecond)-1;
 
 
 console.log("remaining"+remainingDay+"day");
 console.log("remaining"+remainingHour+"hour");
 console.log("remaining"+remainingMinute+"points");
 console.log("remaining"+remainingSecond+"seconds");
 
 console.log("current day"+systemDay+"end day"+endDay);
 console.log("Current time" + systemHour + "When it ends" + endHour);
 console.log("current minute"+systemMinute+"end minute"+endMinute);
 console.log("current second"+systemSecond+"end second"+endSecond);
 
 document.getElementById("font1").innerText=remainingDay+"";
 document.getElementById("font2").innerText=remainingHour+"";
 document.getElementById("font3").innerText=remainingMinute+"";
 document.getElementById("font4").innerText=remainingSecond+"";
 
}
var int=setInterval('torun("2020-12-5 23:59:59")',60);

Table of contents

Effect

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the JavaScript timer principle
  • Detailed explanation of JavaScript timers
  • JavaScript Timer Details
  • JavaScript timer to achieve seamless scrolling of pictures
  • Summary of JavaScript Timer Types

<<:  Usage and difference analysis of replace into and insert into on duplicate key update in MySQL

>>:  Detailed tutorial on minimizing the installation of CentOS 8.1 virtual machine in VirtualBox

Recommend

How to start a Vue.js project

Table of contents 1. Node.js and Vue 2. Run the f...

Use CSS to draw a file upload pattern

As shown below, if it were you, how would you ach...

js implements clock component based on canvas

Canvas has always been an indispensable tag eleme...

VMware Workstation Pro installs Win10 pure version operating system

This article describes the steps to install the p...

Detailed explanation of how to efficiently import multiple .sql files into MySQL

MySQL has multiple ways to import multiple .sql f...

Mysql delete duplicate data to keep the smallest id solution

Search online to delete duplicate data and keep t...

Introduction to installing and configuring JDK under CentOS system

Table of contents Preface Check and uninstall Ope...

Building a KVM virtualization platform on CentOS7 (three ways)

KVM stands for Kernel-based Virtual Machine, whic...

Summary of several common ways to abbreviate javascript code

Table of contents Preface Arrow Functions Master ...

Discussion on CSS style priority and cascading order

In general : [1 important flag] > [4 special fl...

Media query combined with rem layout in CSS3 to adapt to mobile screens

CSS3 syntax: (1rem = 100px for a 750px design) @m...

Linux tutorial on replacing strings using sed command

To replace a string, we need to use the following...