原生js倒計時

來源:互聯網
上載者:User

標籤:display   countdown   mil   span   class   sel   color   cto   art   

<!--倒計時html-->
<a href="#">
<p>本場剩餘</p>
<div class="countdown">
<span></span><i>:</i>
<span></span><i>:</i>
<span></span>
</div>
<p>查看更多<i> ></i></p>
</a>
/*倒計時css樣式*/
.div1>a>div{
height: 26px;
font-size: 0;
text-align: center;
}
.div1>a>div>span{
display: inline-block;
width: 36px;
height: 26px;
line-height: 26px;
text-align: center;
background-color: #392800;
color: #fff;
font-size: 20px;
font-family: "Century Gothic";
font-weight: bold;
}
.div1>a>div>i{
display: inline-block;
width: 16px;
height: 26px;
line-height: 26px;
text-align: center;
font-size: 14px;
font-weight: bold;
color: #392800;
font-style: normal;
position: relative;
top: -8px;
}


// 倒計時js功能區域
/*——start——*/
/*擷取倒計時地區所有span標籤*/
var span = document.querySelectorAll(".countdown>span");
function countdown() {
/*擷取當前毫秒數*/
var dateNewDate = new Date();
var dateNew = dateNewDate.getTime();
/*擷取指定時間毫秒數*/
var dateFutureDate = new Date("2017,8,23,09:00:00");
var dateFuture = dateFutureDate.getTime();
/*儲存小時*/
var hour = parseInt(((dateFuture - dateNew) / 1000 / 60 / 60));//小時
/*儲存分鐘*/
var minit = parseInt(((dateFuture - dateNew) / 1000 / 60) - hour * 60);//分鐘
/*儲存秒*/
var second = parseInt(((dateFuture - dateNew) / 1000) - hour * 60 * 60 - minit * 60);//秒
/*少於兩位元補零*/
if (hour < 10) {
hour = "0" + hour;
} else if (minit < 10) {
minit = "0" + minit;
} else if (second < 10) {
second = "0" + second;
}
/*輸入*/
span[0].innerHTML = hour;
span[1].innerHTML = minit;
span[2].innerHTML = second;
}
/*設定定時器啟動倒計時*/
setInterval("countdown()", 10);
/*——end——*/

原生js倒計時

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.