js通過Date對象實現(xiàn)倒計時效果,具體內(nèi)容如下
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>倒計時動畫</title> <style> div{ text-align:center; height:100px; line-height:100px; } </style> <script> window.onload = function(){ setInterval(FreeTime,1000); } function FreeTime(){ var curTime = Date.now(); var endTime = new Date("2017-10-26 16:00:00"); var allFreeSeconds = (endTime-curTime)/1000; if(allFreeSeconds>0){ var freeDay = Math.floor(allFreeSeconds/(24*60*60)); var freeHour = Math.floor(allFreeSeconds/(60*60) % 24); var freeMinute = Math.floor(allFreeSeconds/60 % 60); var freeSecond = Math.floor(allFreeSeconds%60); document.getElementById("nowTime").innerHTML = "剩余"+freeDay+"天"+freeHour+"時"+freeMinute+"分"+freeSecond+"秒"; } else{ document.getElementById("nowTime").innerHTML = "已結(jié)束"; } } </script> </head> <body> <div> <span id="nowTime"></span> </div> </body> </html>
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com