前言
由于今天在c站意外看到了一篇写京东倒计时的案例,觉得代码写的有问题。于是就在百度和c站搜了一下,发现基本上写的京东倒计时都是有问题的,根本没有完全还原京东的倒计时,逻辑是有问题的,感觉有点误人子弟了,这对刚入门的小白非常的不友好。于是我决定写一下这个案例,还原一下真正的京东倒计时案例
。
我直接把过程给写一下,希望对初学者理解有帮助。
源码
可以在末尾获取。⭐
作为一个前端切图仔,我先去把京东倒计时的背景图片给扒下来把。
倒计时源背景图:
然后按照京东倒计时原版布置一下css样式:
HTML:
<section>
<h2>京东秒杀</h2>
<div class="countdown-desc">
<span>00:00</span>点场 距结束</div>
<div class="hour"></div>
<!-- 小时与分钟之间的冒号 -->
<span class="h_m">:</span>
<div class="minute"></div>
<!-- 分钟与秒之间的冒号 -->
<span class="m_s">:</span>
<div class="second"></div>
</div>
</section>
css:
section {
width: 190px;
height: 260px;
background: url("./images/20210523211517294.png");
overflow: hidden;
position: relative;
}
h2 {
text-align: center;
color: white;
margin-top: 50px;
}
.countdown-desc {
width: 190px;
height: 30px;
position: absolute;
top: 160px;
left: 0;
font-size: 14px;
line-height: 30px;
text-align: center;
color: white;
}
.countdown-desc>span {
font-size: 18px;
margin-right: 2px;
font-weight: bold;
}
.hour,
.minute,
.second {
position: absolute;
top: 200px;
color: #fff;
font-size: 20px;
text-align: center;
line-height: 30px;
width: 30px;
height: 30px;
background: black;
}
.h_m,
.m_s {
font-size: 20px;
font-weight