jquery countdown Timer Implementation code Settimeout/countdown

Source: Internet
Author: User

Let's start with the jquery countdown plugin.

First, introduce the jquery framework and jquery Countdown plugin into the head of the page

The code is as follows Copy Code

<script src= "Jquery.min.js" ></script>
<script src= "Jquery.countdown.min.js" ></script>

Then add the code to render the countdown countdown, such as

The code is as follows Copy Code

<div id= "Counter" ></div>

The final initialization is done.

The code is as follows Copy Code

$ (' #counter '). Countdown ({
Steptime:60,
Format: "Dd:hh:mm:ss",
Starttime:new Date (2012,10,5,1,1,1),//also supports the form of "01:12:32:55"
Digitimages:6,
Digitwidth:53,
Digitheight:77,
Autostart:true,
Image: ' Digits.png ',
Timerend:function () {alert (' xxxx ');},//Set callback method
});

If you do not use plug-ins we can use the settimeout function to instantiate

The code is as follows Copy Code

<title></title>
<script type= "Text/javascript" src= "Js/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" >
var timeout;
var count = 10; Bottom 10.
$ (function () {
Timeout = settimeout (btncount, 1000); 1s perform one btncount
});
Btncount = function () {
Start button
if (count = = 0) {
$ (' #btnSubmit '). attr ("Disabled", "");
$ (' #btnSubmit '). Val ("OK");
Cleartimeout (timeout); The timeout set by the settimeout () method can be canceled
}
else {
count--;
$ (' #btnSubmit '). Val ("Definite" ("+ count.tostring () +");
SetTimeout (Btncount, 1000);
}
};
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:button id= "btnsubmit" runat= "Server" text= "OK" enabled= "false"
onclick= "btnSubmit_Click"/>
</div>
</form>
</body>

One more.

The code is as follows Copy Code
<meta http-equiv= "Content-type" content= "text/html; CHARSET=GBK "/>
<title>jquery to achieve the countdown effect </title>
<script type= "Text/javascript" src= "/jquery.min.js" ></script>

<script type= "Text/javascript" >
var Syssecond;
var intervalobj;

$ (document). Ready (function () {
Syssecond = parseint ($ ("#remainSeconds"). html ()); Here gets the countdown start time
Intervalobj = Window.setinterval (setremaintime, 1000); Interval function, 1 second execution
});

Subtract time by 1 seconds, calculate days, hours, minutes, seconds
function Setremaintime () {
if (Syssecond > 0) {
Syssecond = SysSecond-1;
var second = Math.floor (syssecond% 60); Calculate seconds
var minite = Math.floor ((SYSSECOND/60)% 60); Calculated points
var hour = Math.floor ((syssecond/3600)% 24); Calculated hours
var day = Math.floor ((syssecond/3600)/24); Calculation days

$ ("#remainTime"). HTML (day + "days" + Hour + "hour" + minite + "min" + second + "seconds");
Stop the interval function if {//The remaining time is less than or equal to 0
Window.clearinterval (Intervalobj);
Here you can add events that need to be executed after a countdown time of 0
}
}
</script>


<body>

<div id= "Remainseconds" style= "Display:none" >360000</div>
<div id= "Remaintime" style= "Font-size:20px;font-weight:800;color: #FF9900" ></div>

</body>

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.