• 倒计时simple 天时分秒


    new Date()
    new Date(yyyy,mth,dd,hh,mm,ss); //月从0计数
    .getTime()返回的是一个long型的毫秒
    毫秒转成 秒 分 时 天
    <div id="time" class="shine_red">
        <ul>
            <li id="day">00</li>
            <li id="hours">00</li>
            <li id="mins">00</li>
            <li id="seconds">00</li>
            <li id="minisec" style="display:none">000</li>
        </ul>
    </div>
    <script src="js/jquery.js"></script>
    <!--<script src="http://libs.useso.com/js/jquery/2.1.1/jquery.min.js"></script>-->
    <script type="text/javascript">
    $(function () {
    $("#time").css({
    "left": Math.ceil(($("#content").width() - $("#time").width()) / 2)
            })
        });
    
    var d1, d2, day, h, m, s, ms, d1ms, d2ms, dms, hms, mms;
    dms = 1000 * 60 * 60 * 24;//day
    hms = 1000 * 60 * 60;  //hour
    mms = 1000 * 60;      //minite
    function counter() {
    d1 = new Date(2016, 0, 22, 23, 59, 59);
    d2 = new Date();
    d1ms = d1.getTime();
    d2ms = d2.getTime();
    ms = d1ms - d2ms;
    if (ms <= 0) {
    day = 00;
    h = 00;
    m = 00;
    s = 00;
    ss = 0 % 1000;
            }
    else {
    day = Math.floor(ms / dms);
    h = Math.floor(ms % dms / hms);
    m = Math.floor(ms % hms / mms);
    s = Math.floor(ms % mms / 1000);
    var ss = Math.floor(ms % 1000);
    $('#day').html('<span class="yellow">' + day + '</span>天');
    $('#hours').html('<span class="yellow">' + h + '</span>时');
    $('#mins').html('<span class="yellow">' + m + '</span>分');
    $('#seconds').html('<span class="yellow">' + s + '</span>秒');
            }
    if (day <= 9) {
    $('#day').html('<span class="yellow">0' + day + '</span>天');//0n
    } else {
    $('#day').html('<span class="yellow">' + day + '</span>天');//nn
    }
    if (h <= 9) {
    $('#hours').html('<span class="yellow">0' + h + '</span>时');
            } else {
    $('#hours').html('<span class="yellow">' + h + '</span>时');
            }
    if (m <= 9) {
    $('#mins').html('<span class="yellow">0' + m + '</span>分');
            } else {
    $('#mins').html('<span class="yellow">' + m + '</span>分');
            }
    if (s <= 9) {
    $('#seconds').html('<span class="yellow">0' + s + '</span>秒');
            } else {
    $('#seconds').html('<span class="yellow">' + s + '</span>秒');
            }
    document.getElementById('minisec').innerHTML = ss;
        }
    counter();
    window.setInterval("counter()", 1);
    //-->
    </script>
    


    css
    #time { color:#fff; font-size:0.8rem; padding:0 5px; position: absolute; /* 350px;*/ auto; left: 27%; top: 78%; height: 30px; -webkit-border-radius: 5px; -moz-border-radius: 5px; -o-border-radius: 5px; border-radius: 5px; } #time ul{ list-style: none;margin: 0;padding: 0; } #time ul li{display: inline-block;margin: 0 2px;} .shine_red { -webkit-animation-name: shineRed; -webkit-animation-duration: 3s; -webkit-animation-iteration-count: infinite; } @-webkit-keyframes shineRed { from { -webkit-box-shadow: 0 0 5px #bbb; } 50% { -webkit-box-shadow: 0 0 10px red; } to { -webkit-box-shadow: 0 0 5px #bbb; } }


    <div id="time" class="shine_red">
    <ul>
    <li id="day">00</li>
    <li id="hours">00</li>
    <li id="mins">00</li>
    <li id="seconds">00</li>
    <li id="minisec" style="display:none">000</li>
    </ul>
    </div>
    <script src="js/jquery.js"></script>
    <!--<script src="http://libs.useso.com/js/jquery/2.1.1/jquery.min.js"></script>-->
    <script type="text/javascript">
    $(function () {
    $("#time").css({
    "left": Math.ceil(($("#content").width() - $("#time").width()) / 2)
    })
    });

    var d1, d2, day, h, m, s, ms, d1ms, d2ms, dms, hms, mms;
    dms = 1000 * 60 * 60 * 24;
    hms = 1000 * 60 * 60;
    mms = 1000 * 60;
    function counter() {
    d1 = new Date(2016, 0, 22, 23, 59, 59);
    d2 = new Date();
    d1ms = d1.getTime();
    d2ms = d2.getTime();
    ms = d1ms - d2ms;
    if (ms <= 0) {
    day = 00;
    h = 00;
    m = 00;
    s = 00;
    ss = 0 % 1000;
    }
    else {
    day = Math.floor(ms / dms);
    h = Math.floor(ms % dms / hms);
    m = Math.floor(ms % hms / mms);
    s = Math.floor(ms % mms / 1000);
    var ss = Math.floor(ms % 1000);
    $('#day').html('<span class="yellow">' + day + '</span>天');
    $('#hours').html('<span class="yellow">' + h + '</span>时');
    $('#mins').html('<span class="yellow">' + m + '</span>分');
    $('#seconds').html('<span class="yellow">' + s + '</span>秒');
    }
    if (day <= 9) {
    $('#day').html('<span class="yellow">0' + day + '</span>天');//0n
    } else {
    $('#day').html('<span class="yellow">' + day + '</span>天');//nn
    }
    if (h <= 9) {
    $('#hours').html('<span class="yellow">0' + h + '</span>时');
    } else {
    $('#hours').html('<span class="yellow">' + h + '</span>时');
    }
    if (m <= 9) {
    $('#mins').html('<span class="yellow">0' + m + '</span>分');
    } else {
    $('#mins').html('<span class="yellow">' + m + '</span>分');
    }
    if (s <= 9) {
    $('#seconds').html('<span class="yellow">0' + s + '</span>秒');
    } else {
    $('#seconds').html('<span class="yellow">' + s + '</span>秒');
    }
    document.getElementById('minisec').innerHTML = ss;
    }
    counter();
    window.setInterval("counter()", 1);
    //-->
    </script>

    #time {
    color:#fff;
    font-size:0.8rem;
    padding:0 5px;
    position: absolute;
    /* 350px;*/
    width: auto;
    left: 27%;
    top: 78%;
    height: 30px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    -o-border-radius: 5px;
    border-radius: 5px;
    }


    #time ul{
    list-style: none;margin: 0;padding: 0;
    }
    #time ul li{display: inline-block;margin: 0 2px;}
    .shine_red {
    -webkit-animation-name: shineRed;
    -webkit-animation-duration: 3s;
    -webkit-animation-iteration-count: infinite;
    }
    @-webkit-keyframes shineRed {
    from {
    -webkit-box-shadow: 0 0 5px #bbb;
    }
    50% {
    -webkit-box-shadow: 0 0 10px red;
    }
    to {
    -webkit-box-shadow: 0 0 5px #bbb;
    }
    }

     

  • 相关阅读:
    为了抓包某APP所做的尝试(to be continued)
    VirtualBox的使用的一些Tips 网络配置|硬盘扩充
    斜线和反斜线简要历史,为什么windows和unix采用不同的路径分隔符
    求出二维数组主对角线、次对角线以及周边元素之和
    C#计算两个时间的时间差,精确到年月日时分秒
    C#获取MP3,WMA信息
    C#窗体随意移动
    DEV GridControl小结
    DEV 皮肤的使用
    C#窗体阴影
  • 原文地址:https://www.cnblogs.com/zyjzz/p/5129629.html
Copyright © 2020-2023  润新知