JQuery-like Xiaomi flash sale page countdown effect _ jquery

Source: Internet
Author: User
This article mainly introduces the countdown effect of JQuery-like Xiaomi mobile phone flash sales page. it gives a detailed introduction from functions to implementation principles and main code, and recommends it to friends who have the same requirements. 1. Effect and function description

The time control is used to tell the user how much time is left for an activity, accurate to seconds.

2. implementation principle

First, define the end time of the activity, which must be accurate to milliseconds for the re-year. after obtaining the current year to the second, use the end time minus the current time, the remaining time is shown as much time as possible to determine how long is there before the deadline.

Main code

The code is as follows:


Var startTime = new Date ();
// Obtain the current time
StartTime. setFullYear (2016, 5, 27 );
// Call to set the year
StartTime. setHours (23 );
// Call the hour field to set the specified time
StartTime. setMinutes (59 );
// Call to set the minute field of the specified time
StartTime. setSeconds (59 );
// Call to set the second field of the specified time
StartTime. setMilliseconds (999 );
// Call the millisecond field of the specified time
Var EndTime = startTime. getTime ();
// Obtain the end time
Var nMS = EndTime-NowTime. getTime ();
// The end time minus the current time to obtain the remaining time
Var nD = Math. floor (nMS/(1000*60*60*24 ));
// Define the parameter to get the number of days
Var nH = Math. floor (nMS/(1000*60*60) % 24;
// Get the hour for defining parameters
Var nM = Math. floor (nMS/(1000*60) % 60;
// Get the defined parameter in minutes
Var nS = Math. floor (nMS/1000) % 60;
// Define the parameter to get the second. these are the current time.

3. runtime environment
IE6 IE7 IE8 and above Firefox and Google
Available in Chrome browser

4. create a new file for the compressed packages of all images and decompress the package into the compressed package of the folder Image. you can see at the bottom of the page and download the package without modifying the folder name because it has already been written and the paths in html5 are consistent.

5. replace the encoding type (the UTF-8 has a signature) when saving the html file, so that some Chinese can be displayed normally, will save the type (T) replace with (all files (*. *). Place the html5 and decompressed image folders in the same folder.

6. code

The code is as follows:





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.