JavaScript countdown day, hour, minute, Description of the countdown code

Source: Internet
Author: User
Tags date1

Calling methods

var _timecountdown = new Timecountdown ("sttime1", {startTime: ' 2016-07-30 10:07:55 ',//start time endtime: ' 2016-07-30 10:08:00 ',///end Time Timecallback: "timeoverfun",//callback function});

Countdown.js

/** * @author Wanghaitao * @param sttime1 ID * @param startTime start time * @param endTime end time * @param timecallback callback function * * var _timecountdown = new Timecountdown ("sttime1", {startTime: ' 2016-07-30 10:07:55 ',//start time endtime: ' 2016-07-30 10:08:00 ',///end Time Timecallback: "timeoverfun",//callback function}); */(function (window,undefined) {var timecountdown = function (container, params) {if (! (   This instanceof TIMECOUNTDOWN)) return new Timecountdown (container, params); var defaults = {endTime: ',//titlestarttime: ',//please pass in id, or DOM object lid: ', lefttitle: ' countdown: ',//left name colonstat:false,// Whether to convert a small time to: timecallback:null//close execution of the callback function} params = params | |       {};       var originalparams = {}; For (var param in Params) {if (typeof params[param] = = = ' object ' && params[param]!== null &am p;&! (params[param].nodetype | | params[param] = = Window | | params[param] = = Document | | (typeof Dom7!== ' undefined ' && params[param] instanceof Dom7) | | (typeof jQuery!== ' undefined ' && params[param] (instanceof JQuery))) {originalparams[param] = {};                For (var deepparam in params[param]) {originalparams[param][deepparam] = params[param][deepparam];            }} Else {originalparams[param] = params[param]; }} for (var def in defaults) {if (typeof params[def] = = = ' undefined ') {params[def] =            defaults[def];                    } else if (typeof params[def] = = = ' Object ') {for (var deepdef in Defaults[def]) { If (typeof params[def][deepdef] = = = ' undefined ') {params[def][deepdef] = DEFAULTS[DEF][DEEPD                    ef];        }}}} var s = this; params s.params = params;        S.container = container; S.currentbreakpoint = Undefined;s.calculatetime = function () {var startTime = S.vert (this.params.startTime); var endTime = S.vert(this.params.endTime); var time = endtime-starttime; The number of milliseconds of the time difference; S.vert = function (time) {if (typeof time = = "undefined" | | time== "") {return false;} var strtime = (time). Replace (/-/g, "/"), var date1 = new Date (strtime); return parseint (date1.gettime ());} S.ntime = s.calculatetime (); s.countdown ();};    Timecountdown.prototype = {countdown:function () {var interval = 1000;//ms var time; this.ntime = this.ntime-interval;  var leave1 = this.ntime;//the Number of milliseconds remaining after the calculation of the number of days var t = Math.floor (math.floor ((leave1/(3600*1000))/24);  var hleave = this.ntime% ((24*3600*1000)); Convert the remaining number of milliseconds to hours var h = Math.floor (hleave/(3600*1000)) < 10?        "0" + math.floor (hleave/(3600*1000)): math.floor (hleave/(3600*1000)); var leave2 = this.ntime% (3600*1000); Number of milliseconds left after calculation of Hours//after conversion hours, the remaining milliseconds converted to minutes var m = Math.floor (leave2/(60*1000)) < 10?      "0" + math.floor (leave2/(60*1000)): math.floor (leave2/(60*1000));//convert minutes after conversion, the remaining number of milliseconds to the second var leave3 = leave2% (60*1000); Count the number of milliseconds remaining after the number of minutes var s = Math.Round (leave3/1000) < 10? "0" + math.round (leave3/1000): math.round (leave3/1000); If (!this.params.colonstat) {if (t = = 0) {time = this.params.lefttitle+ "<span>" + H + "</span><label> when & Lt;/label><span> "+ m +" </span><label> min </label><span> "+ s +" </span><label  > Seconds <label> "; }else{time = this.params.lefttitle+ "<span>" + t + "</span><label> Day </label><span>" + H + "& Lt;/span><label> </label><span> "+ m +" </span><label> min </label><span> "+ S +" </span><label> sec <label> ";}} Else{time = this.params.lefttitle+ "<span>" + H + "</span><label>:</label><span>" + M + "&L  T;/span><label>:</label><span> "+ s +" </span><label><label> "; }var callbacktime = T+h+m+s;document.queryselector ("#" +this.container). innerHTML = time;if (callbacktime <= 0) {eval (this.params.timeCallBack); return false;} var that = This;settimeout (function () {that.countdown ();},interval);}} Window. Timecountdown=timecountdown;}) (window,undefined);

  

JavaScript countdown day, hour, minute, Description of the countdown code

Related Article

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.