< 返回新闻公共列表
jQuery倒计时代码 显示天、小时、分钟和秒数
发布时间:2019-11-21 12:03:08
- <!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>
- <title>精美倒计时</title>
- <style>
- *{ padding:0; margin:0;}
- .colockbox{width:250px;height:30px;background:url(/jscss/demoimg/201312/colockbg.png) no-repeat;overflow: hidden; color:#000000;}
- .colockbox span{float:left;display:block;width:40px;height:29px;line-height:29px;font-size:20px; font-weight:bold;text-align:center;color:#ffffff; margin-right:22px;}
- </style>
- <script type="text/javascript" src="/ajaxjs/jquery-1.6.2.min.js"></script>
- <script type="text/javascript">
- $(function(){
- countDown("2015/10/1 10:00:00","#colockbox1");
- });
- function countDown(time,id){
- var day_elem = $(id).find('.day');
- var hour_elem = $(id).find('.hour');
- var minute_elem = $(id).find('.minute');
- var second_elem = $(id).find('.second');
- var end_time = new Date(time).getTime(),//月份是实际月份-1
- sys_second = (end_time-new Date().getTime())/1000;
- var timer = setInterval(function(){
- if (sys_second > 1) {
- sys_second -= 1;
- var day = Math.floor((sys_second / 3600) / 24);
- var hour = Math.floor((sys_second / 3600) % 24);
- var minute = Math.floor((sys_second / 60) % 60);
- var second = Math.floor(sys_second % 60);
- day_elem && $(day_elem).text(day);//计算天
- $(hour_elem).text(hour<10?"0"+hour:hour);//计算小时
- $(minute_elem).text(minute<10?"0"+minute:minute);//计算分钟
- $(second_elem).text(second<10?"0"+second:second);//计算秒杀
- } else {
- clearInterval(timer);
- }
- }, 1000);
- }
- </script>
- </head>
- <body>
- <div class="colockbox" id="colockbox1"> <span class="day">00</span> <span class="hour">00</span> <span class="minute">00</span> <span class="second">00</span> </div>
- </body>
- </html>
所需要的背景图
▇天▇时▇分▇秒