代码展示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
}
.box {
width: 320px;
height: 280px;
border: 10px solid #f2f2f2;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
.box-top {
position: absolute;
right: 0;
width: 100px;
height: 40px;
background-color: coral;
text-align: center;
line-height: 40px;
color: #fff;
}
.bottom {
width: 120px;
height: 40px;
border: 1px solid #ccc;
text-align: center;
line-height: 40px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto
}
</style>
<script>
var endTime = new Date("2023-10-31T10:00:00Z");
var countdownTimer = setInterval(updateCountdown, 1000);
function updateCountdown() {
var currentTime = new Date();
var remainingTime = Math.floor((endTime - currentTime) / 1000);
if (remainingTime <= 0) {
clearInterval(countdownTimer);
document.getElementById("timer").innerHTML = "拍卖已结束";
return;
}
var minutes = Math.floor(remainingTime / 60);
var seconds = Math.floor(remainingTime % 60);
var countdownStr = minutes + "分钟 " + seconds + "秒";
document.getElementById("timer").innerHTML = countdownStr;
}
</script>
</head>
<body>
<div class="box">
<div class="box-top">
即将拍卖
</div>
<div id="countdown" class="bottom"> <span id="timer" class="bottom"> </span></div>
</div>
</body>
</html>