Chào các bạn, theo yêu cầu của một số bạn. Thì hôm nay mình sẽ chia sẻ đến các bạn một code cho phép đếm ngược đến ngày
Tết Kỷ Hợi 2019, mình đặt title là dành cho blog, nhưng vẫn dùng được cho các thể loại web khác nhé, code bởi
Mạnh Tuấn J2TeaM, mình đem về viết lại CSS. Bên dưới là Hướng dẫn và Code
HƯỚNG DẪN CÁCH LÀM:
Bạn tiến hành vào
Dashboard blog của bạn -->
Bố cục -->
Thêm tiện ích -->
HTML/Javascript --> Trong ô
Nội dung các bạn chèn đoạn code phía dưới vào
trong nó và nhấn
Lưu để hoàn thành lưu code vào blog.
<!-- Countdown -->
<style>
/* Countdown */
#countdown{float:left;width:100%;height:130px;box-sizing:border-box;margin-top:30px}
#timer{padding-top:0}
#timer div{width:65px;height:65px;line-height:45px;z-index:199;background:transparent;box-shadow:0 0 0 4px rgb(78, 50, 136);border-radius:50%;text-align:center;font-size:20px;font-weight:700;color:#fff;display:inline-block;float:left;margin:0 9px;color:rgb(78, 50, 136)}
#timer div:nth-child(1),{margin-left:0}
#timer div:last-child{margin-right:0}
#timer h2{color:#222}
h2.title-countdown{font-size:23.5px!important;font-weight:700;text-transform:uppercase;margin-bottom:20px;font-family:'Utm Avo',sans-serif;border-bottom:2px solid #222}
#timer span{color:rgb(78, 50, 136);margin-bottom:20px;font-size:12px;display:block;transform:translate(0,-52%)}
#days,#hours,#minutes{color:#fb5182}
.title-countdown strong{color:#4e3288}
@media screen and (max-width: 440px) {
#timer div{width:50px!important;height:50px!important;line-height:35px!important;font-size:15px!important}
#timer span{font-size:8px;transform:translate(0,-52%)!important}
.title-countdown span{font-size:18px!important}
}
</style>
<div id='countdown'>
<div id='timer'>
<h2 class='title-countdown'>Đếm ngược ngày đến <strong>Tết</strong></h2>
<div id='days'></div>
<div id='hours'></div>
<div id='minutes'></div>
<div id='seconds'></div>
</div>
</div>
<script type='text/javascript'>
//<![CDATA[
// Countdown tet
// Countdown tet
let timeout = null;
function makeTimer() {
// Edit Here
//---- let endTime = new Date("'02/03/2019 23:59:59 GMT+0700 (SE Asia Standard Time)"); ----
let endTime = new Date("'02/05/2019 23:59:59 GMT+0700 (SE Asia Standard Time)");
endTime = (Date.parse(endTime) / 1000);
let now = new Date();
now = (Date.parse(now) / 1000);
let timeLeft = endTime - now,
days = Math.floor(timeLeft / 86400),
hours = Math.floor((timeLeft - (days * 86400)) / 3600),
minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600)) / 60),
seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
if (hours === 0 && minutes === 0 && seconds === 0) {
clearTimeout(timeout);
} else {
if (hours < "10") {
hours = "0" + hours;
}
if (minutes < "10") {
minutes = "0" + minutes;
}
if (seconds < "10") {
seconds = "0" + seconds;
}
$("#days").html(days + "Ngày");
$("#hours").html(hours + "Giờ");
$("#minutes").html(minutes + "Phút");
$("#seconds").html(seconds + "Giây");
timeout = setTimeout(makeTimer, 1000);
}
}
makeTimer();
//]]>
</script>
<!-- End coutdown -->
Chúc bạn thành công !
No comments