DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> javascript實現促銷倒計時+fixed固定在底部
javascript實現促銷倒計時+fixed固定在底部
編輯:關於JavaScript     
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>無標題文檔</title>
<style>
#lefttime3 { background: url(timerbg.jpg) no-repeat left center; width:1018px;height:55px;
font-size:40px;line-height: 55px;font-family: MS Yahei,Microsoft YaHei;
color: #f00;color:rgb(255,205,1);
}
#day{ margin-left: 592px;}
#hour { margin-left:40px; }
#min { margin-left: 39px;}
#sec { margin-left: 37px;}
</style>
<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.exec(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.documentElement.scrollLeft + document.documentElement.clientWidth - 312) + "px";
}, 80);
}
}
</script>
</head>

<body style="height:300000px;">
<div id="lll" style="margin:10px;padding:20px; border:solid 2px #DDD; background:#fc6;height:300px;"></div>
<div id="lefttime3" style="position:fixed;bottom:0px;right:0px;"><span id="day"></span><span id="hour"></span><span id="min"></span><span id="sec"></span></div>
<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);//倒計時

ieFixed('lefttime3'); //固定在底部
</script>
</body>
</html>

1)兼容IE6
2)自動倒計時,輸入的數字必須是時間,單位毫秒。
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved