首页  >  文章  >  web前端  >  javascript实现促销倒计时+fixed固定在底部_javascript技巧

javascript实现促销倒计时+fixed固定在底部_javascript技巧

WBOY
WBOY原创
2016-05-16 17:22:171110浏览
复制代码 代码如下:





无标题文档

<script> <br><br>var djs = function(d,o) <BR>{ <BR>var f = { <BR>zero: function(n){ <BR>var n = parseInt(n, 10); <BR>if(n > 0) { <BR>if(n <= 9) n = '0' + n; <BR>return String(n); <BR>} else { <BR>return '00'; <BR>} <BR>}, <BR>run: function(){ <BR>var ts = Math.round((new Date(d).getTime() - new Date().getTime()) / 1000); <BR>if(o && ts > 0) <BR>{ <BR>var yy = Math.floor(ts / 31556926); <BR>var mm = Math.floor(ts / 2629744); mm = mm > 0 ? mm%12 : '00'; <BR>var dd = Math.floor(ts / 86400); dd = dd > 0 ? dd%30 : '00'; <BR>var hh = Math.floor(ts / 3600); hh = hh > 0 ? hh%24 : '00'; <BR>var ii = Math.floor(ts / 60); ii = ii > 0 ? ii%60 : '00'; <BR>var ss = Math.floor(ts % 60); <br><br>if(o.y) o.y.innerHTML = f.zero(yy); <BR>if(o.m) o.m.innerHTML = f.zero(mm); <BR>if(o.d) o.d.innerHTML = f.zero(dd); <BR>if(o.h) o.h.innerHTML = f.zero(hh); <BR>if(o.i) o.i.innerHTML = f.zero(ii); <BR>if(o.s) o.s.innerHTML = f.zero(ss); <BR>} <br><br>window.setTimeout(f.run,1000); <BR>} <BR>} <br><br>f.run(); <BR>} <br><br>function ieFixed(id) <BR>{ <BR>var isIE = (document.all) ? true : false; <BR>var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6); <BR>var obj = document.getElementById(id).style; <BR>if (isIE6 && obj) <BR>{ <BR>obj.position = "absolute"; <BR>obj.bottom = "0px"; <BR>obj.right = "0px"; <BR>var tm = window.setInterval(function(){ <BR>obj.marginBottom = "0px"; <BR>obj.left = ( document.documentElement.scrollLeft + document.documentElement.clientWidth - 312) + "px"; <BR>}, 80); <BR>} <BR>} <BR></script>





<script> <BR>var d = new Date().getTime() + 3600*24*1000; <BR>var d = 1379572933131; <BR>var o = { <BR>d: document.getElementById('day'), <BR>h: document.getElementById('hour'), <BR>i: document.getElementById('min'), <BR>s: document.getElementById('sec') <BR>} <BR>djs(d,o);//倒计时 <br><br>ieFixed('lefttime3'); //固定在底部 <BR></script>



1)兼容IE6
2)自动倒计时,输入的数字必须是时间,单位毫秒。
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn