CSS3实现倒计时

CSS3实现倒计时小程序,界面如下:

代码如下:

<style>
        body,html{
            margin:0px;
            height:100%;
        }
        body{background: #000;
            overflow: hidden;}
        div{ width:200px;
            height:200px;
            border: 5px #fff solid;
            border-radius: 50%;
            position: relative;
            margin: 0 auto;
            text-align: center;
            -webkit-transition: all .5s ease-in .1s;
            top: 50%;
            left: 50%;
            margin-left: -100px;
            margin-top: -100px;
        }
        div>span{  color: #fff;
            display: inline-block;
            position: absolute;
            left: 50%;
            top: 50%;
            font-size: 145px;
            line-height: 74%;
            font-weight: bolder;
            font-family: Arial, Helvetica, sans-serif;
            -webkit-transform: translate(-50%, -50%);
            width: 100%;
        }
        .bigbang{
            -webkit-transform: scale(10);
            opacity: 0;
        }
    </style>

HTML代码:

<div>
    <span id="num">10</span>
</div>

JS代码:

<script>
    function djs(){
        var obj=document.getElementById('num');
        var num=obj.innerText;
        obj.innerText=num-1;
        if(num-1==0){
            clearInterval(ds);
            obj.parentElement.className='bigbang';
            setTimeout(function(){
                obj.parentElement.className='';
                obj.innerHTML='时间到';
                obj.style.fontSize='58px';
                obj.parentElement.style.background='red';
            },600)
        }
    }
    //djs();
    var ds=setInterval(djs,1000);
</script>

 

posted @ 2015-08-03 16:51  Alec-Yin  阅读(3973)  评论(0编辑  收藏  举报
更多前端博客,访问:http://lhyin.com