JavaScript实现京东商城秒杀倒计时
·

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>时间日期对象</title>
<!-- <link rel="stylesheet" href="css/style.css"> -->
<style>
.jingdong {
width: 190px;
height: 260px;
padding-top: 10px;
background-image: url(jingdong.png);
margin: 50px auto;
}
h2 {
margin-top: 31px;
font-size: 30px;
}
h2,
p {
color: #fff;
font-weight: 700;
text-align: center;
}
p {
margin-top: 80px;
font-size: 16px;
}
p strong {
font-size: 18px;
}
.time {
position: relative;
width: 130px;
height: 30px;
margin: 0 auto;
}
span {
position: relative;
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
background-color: #2f3430;
color: #fff;
margin: 0 5px;
font-weight: bold;
font-size: 18px;
}
span:nth-child(-n + 2)::after {
content: ":";
display: inline-block;
position: absolute;
bottom: 0;
left: 27px;
width: 20px;
height: 30px;
color: #fff;
font-size: 18px;
}
</style>
</head>
<body>
<div class="jingdong">
<h2>京东秒杀</h2>
<p><strong id="clock">21:00</strong>点场 距结束</p> <!--显示当前为几点场,js中用Session变量保存-->
<div class="time">
<span id="shi"></span>
<span id="fen"></span>
<span id="miao"></span>
</div>
</div>
<script>
function countTime(){
var now = new Date();
var nowHour = now.getHours();
var Session = "";
var end = new Date();
if(nowHour>=6){
end.setMinutes(0);end.setSeconds(0);
if(nowHour >= 6 && nowHour<10){
Session = "8:00";
end.setHours(8);
}
if(nowHour >= 8 && nowHour<10){
Session = "10:00";
end.setHours(10);
}
if(nowHour >= 10 && nowHour<12){
Session = "12:00";
end.setHours(12);
}
if(nowHour >= 12 && nowHour<14){
Session = "14:00";
end.setHours(14);
}
if(nowHour >= 14 && nowHour<16){
Session = "16:00";
end.setHours(16);
}
if(nowHour >= 16 && nowHour<18){
Session = "18:00";
end.setHours(18);
}
if(nowHour >= 18 && nowHour<20){
Session = "20:00";
end.setHours(20);
}
if(nowHour >= 20 && nowHour<22){
Session = "22:00";
end.setHours(22);
}
if(nowHour >= 22){
Session = "0:00";
end.setHours(24);
}
} else {
Session = "暂时没有秒杀";
}
document.getElementById("clock").innerHTML = Session;
var lag = (end-now)/1000;
var hour = parseInt(lag/(60*60));
var minute=Math.floor((lag/60)%60);
var second = Math.floor(lag%60);
hour = hour < 10 ? "0"+hour:hour;
minute = minute < 10 ? "0"+minute:minute;
second = second < 10 ? "0"+second:second;
document.getElementById("shi").innerHTML = hour;
document.getElementById("fen").innerHTML = minute;
document.getElementById("miao").innerHTML = second;
setTimeout("countTime()",1000);
}
window.onload = countTime;
</script>
</body>
</html>
更多推荐



所有评论(0)