原生js倒计时动画

代码语言:html

所属分类:动画

代码描述:原生js倒计时动画

代码标签: 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<link href="https://fonts.googleapis.com/css2?family=Sen&display=swap" rel="stylesheet" />
<style>
:root {
    --counter-font-size: 10rem;
    --counter-font-size-neg: -10rem;
}

html {
    font-size: 10px;
}

*,
*:before,
*:after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Sen', sans-serif;
    height: 100vh;
    background-color: rgb(29, 29, 32);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.counter-box {
    position: fixed;
    top: 40%;
    left: 0;
    padding: 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

.digit-box {
    overflow-y: hidden;
    position: relative;
    height: var(--counter-font-size);
    width: 100px;
    display: flex;
    justify-content: center;
}

.digit {
    font-size: var(--counter-font-size);
    height: var(--counter-font-size);
    color: #1280bf;
    transition: top 0.5s;
    line-height: 1;
}

.top {
    position: absolute;
    top: var(--counter-font-size-neg);
}

.middle {
    position: absolute;
    top: 0;
}

.bottom {
    position: absolute;
    top: var(--counter-font-size);
}

.button-group {
    display: flex;
    justify-content: center;
}

.button {
    background-color: #1280bf;
    color: #fff;
    font-size: 1.6rem;
    border: none;
    padding: 0 2.2rem;
    cursor: pointer;
    border-radius: 5px;
    margin-left: 5px;
}

.button:hover {
    background-color: #5ba5cf;
}

.form-container {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 10px;
}

label {
    color: #fff;
    font-size: 2.2rem;
    margin-right: 2px;
}

input[type='number'] {
    font-size: 2.2rem;
    border-radius: 5px;
    border: none;
    padding: 5px;
    background-color: rgb(65, 65, 73);
    color: #fff;
}
</style>

</head>

<body>
<section class="container">
<div class="form-container">
<div class="form-group">
<label for="speed-input">Speed (ms)</label>
<input type="number" id="speed-input" value="1000" />
</div>
<div class="button-group">
<button class="button" id="start-button">Start</button>
<button class="button" id="stop-button">Stop</button>
</div>
</div>
<div class="counter-box">
<div class="digit-box">
<span class="digit top">1</span>
<span class="digit middle">0</span>
<span class="digit bottom">-1</span>
</div>
<div class="digit-box">
<span class="digit top">1</span>
<span class="digit middle">0</span>
<span class="digit bottom">-1</span>
</div>
<div class="digit-b.........完整代码请登录后点击上方下载按钮下载查看

网友评论0