js促销倒数计时器

1.效果图

2.实现代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒数计时器</title>
    <script src="statics/js/jquery-1.8.3.min.js"></script>
</head>

<style type="text/css">
   .timer{
       font-size: larger;
       color:#C71585;

   }

    .andy{
        margin: 10px auto;
        background-color: whitesmoke;
        height: 88px;
        line-height: 88px;
        text-align: center;
        width: 240px;
        padding-top: 10px;
        border: dotted 3px gainsboro;
        border-radius: 5px;
        box-shadow: 5px 5px 5px #888888;
    }
    .day{color: #6A5ACD}

</style>
<body>

    <div id="andy timer" class="andy timer">

    </div>

</body>
</html>

<script type="text/javascript">



    var interval=1000;

    function ShowTimer(endYear,endMonth,endDay,divId) {
        var now=new Date();

        console.log("now="+now);

        var endDate=new Date(endYear,endMonth-1,endDay);

        console.log("endDate="+endDate);

        //getTime()获取的值/1000=秒数
        var leftTime=endDate.getTime() - now.getTime();

        console.log("leftTime="+leftTime);

        var leftSecond=parseInt(leftTime/1000);

        console.log("leftSecond="+leftSecond);

        var day=Math.floor(leftSecond/(60*60*24));

        console.log("day="+day);

        var hour=Math.floor((leftSecond-day*24*60*60)/3600);

        console.log("hour="+hour);

        var minute=Math.floor((leftSecond - day * 24 * 60 * 60 - hour * 3600) / 60);

        console.log("hour="+hour);

        var second = Math.floor(leftSecond - day * 24 * 60 * 60 - hour * 3600 - minute * 60);
        console.log("second="+second);

        var htmlElement=document.getElementById(divId);
        htmlElement.innerHTML = "<span class='day'><b class='timer'>" + day + "</b></span>" +
            "<span class='day'><b class='timer'>" + hour + "</b></span>" +
            "<span class='day'><b class='timer'>" + minute + "</b></span>" +
            "<span class='day'><b class='timer'>" + second + "</b>";
    }

    window.setInterval(function () { ShowTimer(2017, 7, 20, 'andy timer'); }, interval);


</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值