Javascript countdown + fixed at the bottom _ javascript tips-js tutorial

Source: Internet
Author: User
A good example is a sales countdown implemented using javascript, with fixed at the bottom and compatible with ie6. If you like it, refer The Code is as follows:






Untitled document

Script

Var djs = function (d, o)
{
Var f = {
Zero: function (n ){
Var n = parseInt (n, 10 );
If (n> 0 ){
If (n <= 9) n = '0' + n;
Return String (n );
} Else {
Return '00 ';
}
},
Run: function (){
Var ts = Math. round (new Date (d). getTime ()-new Date (). getTime ()/1000 );
If (o & ts> 0)
{
Var yy = Math. floor (ts/31556926 );
Var mm = Math. floor (ts/2629744); mm = mm> 0? Mm % 12: '00 ';
Var dd = Math. floor (ts/86400); dd = dd> 0? Dd % 30: '00 ';
Var hh = Math. floor (ts/3600); hh = hh> 0? Hh % 24: '00 ';
Var ii = Math. floor (ts/60); ii = ii> 0? Ii % 60: '00 ';
Var ss = Math. floor (ts % 60 );

If (o. y) o. y. innerHTML = f. zero (yy );
If (o. m) o. m. innerHTML = f. zero (mm );
If (o. d) o. d. innerHTML = f. zero (dd );
If (o. h) o. h. innerHTML = f. zero (hh );
If (o. I) o. I. innerHTML = f. zero (ii );
If (o. s) o. s. innerHTML = f. zero (ss );
}

Window. setTimeout (f. run, 1000 );
}
}

F. run ();
}

Function ieFixed (id)
{
Var isIE = (document. all )? True: false;
Var isIE6 = isIE & ([/MSIE (\ d) \. 0/I .exe c (navigator. userAgent)] [0] [1] = 6 );
Var obj = document. getElementById (id). style;
If (isIE6 & obj)
{
Obj. position = "absolute ";
Obj. bottom = "0px ";
Obj. right = "0px ";
Var tm = window. setInterval (function (){
Obj. marginBottom = "0px ";
Obj. left = (document.doc umentElement. scrollLeft + document.doc umentElement. clientWidth-312) + "px ";
}, 80 );
}
}
Script





Script
Var d = new Date (). getTime () + 3600*24*1000;
Var d = 1379572933131;
Var o = {
D: document. getElementById ('day '),
H: document. getElementById ('hour '),
I: document. getElementById ('Min '),
S: document. getElementById ('sec ')
}
Djs (d, o); // countdown

IeFixed ('lefttime3'); // fixed at the bottom
Script



1) compatible with IE6
2) Automatic countdown. The input number must be time, in milliseconds.
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.