<section>
<div class="container">
<h1>00:00</h1>
</div>
</section>
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ... </head>
<body>
</body>
CSS
格式化
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
h1 {
font-family: "Montserrat";
font-size: 90px;
}
* {
box-sizing: border-box;
}
body {
overflow-x: hidden;
}
.float-text {
display: inline-block;
position: absolute;
right: 10px;
bottom: 10px;
width: fit-content;
background-color: #192227;
color: whitesmoke;
font-family: "Montserrat";
text-transform: capitalize;
font-size: 15px;
padding: 10px 20px;
border-radius: 4px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.226);
cursor: pointer;
border: 1px solid white;
}
.float-card-info {
width: 300px;
position: absolute;
background-color: #263238;
border: 2px solid white;
overflow: hidden;
bottom: 5px;
right: -100%;
padding: 30px;
border-radius: 8px;
transition: 0.5s ease-in-out right;
}
.float-card-info p {
color: white;
font-size: 20px;
font-family: "Montserrat";
text-transform: capitalize;
width: 100%;
font-weight: 500;
text-align: center;
margin-bottom: 20px;
}
.gg-youtube {
--ggs: 1.5;
}
.float-card-info .icons {
width: 120px;
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
flex-direction: row;
margin-bottom: 20px;
}
.float-card-info .icons a {
display: inline-block;
cursor: pointer;
color: whitesmoke;
}
.float-card-info .icons a:hover {
color: rgb(127, 127, 129);
}
.float-card-info .link {
width: 100%;
display: block;
text-decoration: none;
color: whitesmoke;
font-family: "Montserrat";
font-size: 14px;
text-align: center;
margin-top: 5px;
}
.gg-close-r {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
}
.float-card-info.active {
right: 5px;
bottom: 5px;
}
.float-card-info .hire {
background-color: #181e22;
text-transform: uppercase;
letter-spacing: 0.5px;
font-size: 18px;
border-radius: 6px;
width: fit-content;
margin: 0 auto;
padding: 10px 20px;
margin-top: 20px;
}
JS
格式化
let timeSecond = 30;
const timeH = document.querySelector("h1");
displayTime(timeSecond);
const countDown = setInterval(() => {
timeSecond--;
displayTime(timeSecond);
if (timeSecond == 0 || timeSecond < 1) {
endCount();
clearInterval(countDown);
}
}, 1000);
function displayTime(second) {
const min = Math.floor(second / 60);
const sec = Math.floor(second % 60);
timeH.innerHTML = `
${min < 10 ? "0" : ""}${min}:${sec < 10 ? "0" : ""}${sec}
`;
}
function endCount() {
timeH.innerHTML = "时间到";
}