Shopping Mall product countdown instance based on javascript, javascript Shopping Mall

Source: Internet
Author: User

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!

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.