Shopping Mall product countdown instance based on javascript, javascript Shopping Mall
Let's not talk about it much. Let's take a look at the instance Code together with the small Editor.
Js:
/*** Author: Black_Jay success * downCount: Countdown to time conversion */(function ($) {$. fn. downCount = function (options, callback) {var settings = $. extend ({date: null, offset: null}, options); if (! Settings. date) {$. error ('date is not defined. ');} if (! Date. parse (settings. date) {$. error ('encrect date format, it shocould look like this, 12:00:00. ');} var container = this; var currentDate = function () {var date = new Date ();/* var utc = date. getTime () + (date. getTimezoneOffset () * 60000); var new_date = new Date (utc + (3600000 * settings. offset); */return date;}; function countdown () {var target_date = new Date (settings. date), cur 1__date = currentDate (); var difference = target_date-current_date; if (difference <0) {clearInterval (interval); // cancel setInterval () if (callback & typeof callback = 'function') callback (); return;} var _ second = 1000, _ minute = _ second * 60, _ hour = _ minute * 60, _ day = _ hour * 24; var days = Math. floor (difference/_ day), hours = Math. floor (difference % _ day)/_ hour) + (da Ys * 24), minutes = Math. floor (difference % _ hour)/_ minute), seconds = Math. floor (difference % _ minute)/_ second); days = (String (days ). length> = 2 )? Days: '0' + days; hours = (String (hours). length> = 2 )? Hours: '0' + hours; minutes = (String (minutes). length> = 2 )? Minutes: '0' + minutes; seconds = (String (seconds). length> = 2 )? Seconds: '0' + seconds; container. find ('. hours '). text (hours); container. find ('. minutes '). text (minutes); container. find ('. seconds '). text (seconds) ;}; var interval = setInterval (countdown, 1000) ;}}) (jQuery );
Html:
<! -- Display Star in countdown --> <p class = "countdown"> <span class = "hours"> 00 </span>: <span class = "minutes"> 00 </span>: <span class = "seconds"> 00 </span> </p> <! -- Countdown End -->
Enter the end time you want.
JS:
$ ('. Countdown '). downCount ({date: '2014/1/0 13:45:00 ', offset: + 10}, function () {alert ('second kill finished ');});
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!