JQuery countdown, simple code

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn. This article takes the countdown of the Group Buying website as an example to give the end time and the end time of the Spring Festival in 2016 to the three commodities.


The demo and Free Download Links are available at the bottom of the page. If you want to see more Js Special Effects, Website source code, Js tutorialPlease visit the http://www.sucaihuo.com/js and DEMO, most of all can be downloaded for free. We define the end time stamp for the three items respectively, that is, the class is the value of the ". endtime" attribute.



  • Mayiner 2015 Korean new printing summer dress





  • New two-piece set of 2015 summer clothes on amoeba




  • New Korean version of yingcurtain 2015 Spring women's clothing




JQuery
The code in setInterval is executed every 100 milliseconds at a time for each item. Then, the each () method traverses and computes the countdown of each item, in the unit of days, hours, minutes, and seconds.
Var time_current = (new Date (). valueOf (); // get the current time
$ (Function (){
Var dateTime = new Date ();
Var difference = dateTime. getTime ()-time_current;

SetInterval (function (){
$ (". Endtime"). each (function (){
Var obj = $ (this );
Var endTime = new Date (parseInt (obj. attr ('value') * 1000 );
Var nowTime = new Date ();
Var nMS = endTime. getTime ()-nowTime. getTime () + difference;
Var myD = Math. floor (nMS/(1000*60*60*24 ));
Var myH = Math. floor (nMS/(1000*60*60) % 24;
Var myM = Math. floor (nMS/(1000*60) % 60;
Var myS = Math. floor (nMS/1000) % 60;
Var myMS = Math. floor (nMS/100) % 10;
If (myD> = 0 ){
Var str = myD + "day" + myH + "Hour" + myM + "Minute" + myS + "." + myMS + "second ";
} Else {
Var str = "ended! ";
}
Obj.html (str );
});
},
100 );
});
See this special effect demo and free download, visit the http://www.sucaihuo.com/js/36.html

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.