JS倒计时

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>倒计时效果</title>

<style type="text/css">
.wrap {width:400px; margin:50px auto; color:#333; font-family:'\5FAE\8F6F\96C5\9ED1';}
.wrap-date {font-size:24px; list-style:none outside none; margin-top:8px;}
.wrap-date li {width:80px; display:inline-block; *display:inline; *zoom:1; text-align:center; background:hotPink; padding:1px 0 5px; margin-right:3px;}
.date {font-family:Tahoma; font-size:50px; color:#fff;}
#endTips {color:#999; background:#e9e9e9; line-height:2.4em; text-align:center; margin-top:15px;}

.author {color:#090; font-size:12px; margin-top:50px; line-height:1.8; text-align:right;}
</style>

<script type="text/javascript">
     // 创建定时器
    var timer = window.setInterval(function(){
        RefreshTime(2018,12,23);  // 活动截止时间
    },1000);

    function RefreshTime(year,month,day){

        // 获取本地当前时间,截止时间 - 当前时间 = 倒计时时间
        var Today = new Date();     
        var endDate = new Date(year, month-1, day); 
        var leftTime = endDate.getTime() - Today.getTime();
        var leftSecond = parseInt(leftTime / 1000);
        var Day = Math.floor(leftSecond / (60*60*24));
        var Hour = Math.floor((leftSecond - Day*24*60*60) / 3600);
        var Minute=Math.floor((leftSecond - Day*24*60*60 - Hour*3600) / 60); 
        var Second=Math.floor(leftSecond - Day*24*60*60 - Hour*3600 - Minute*60);

        if(Day < "0"){ 
            clearInterval(timer); // 清除定时器
            document.getElementById("endTips").innerHTML = "活动已结束";
            document.getElementById("wrapDate").style.display = "none";
            return;
        }

        // 写入容器
        document.getElementById("timeDay").innerHTML = Day;
        document.getElementById("timeHour").innerHTML = Hour;
        document.getElementById("timeMin").innerHTML = Minute;
        document.getElementById("timeSec").innerHTML = Second;
    }
</script>

</head>

<body>

<div class="wrap">
距活动结束仅剩:
    <ul class="wrap-date" id="wrapDate">
        <li><span id="timeDay" class="date">0</span><br /></li><!--
     --><li><span id="timeHour" class="date">0</span><br /></li><!--
     --><li><span id="timeMin" class="date">0</span><br /></li><!--
     --><li><span id="timeSec" class="date">0</span><br /></li>
    </ul>  
    <div id="endTips"></div>     


    <p class="author">—— Wing Meng 2016.12.03</p>
</div>

</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值