web之利用延迟实现复杂动画、animation

文章目录


效果图


html

html 复制代码
<div class="container">
    <div class="ball"></div>
    <input type="range" min="0" max="1" step="0.01" />
</div>

style

css 复制代码
body {
    display: flex;
    justify-content: center;
}

.container {
    margin-top: 30px;
}

.ball {
    --delay: 0s;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #ff0000;
    margin-bottom: 50px;
    animation: move 1s var(--delay) linear forwards paused;
    /* animation-play-state: running; */
    /* animation-play-state: paused; */
}

@keyframes move {
    50% {
        transform: translate(100px) scale(1.5);
    }

    100% {
        transform: translate(200px) scale(1);
    }
}

JavaScript

javascript 复制代码
// js方式实现(不考虑此方案)
// let inp = document.querySelector('input');
// inp.oninput = function () {
//     console.log(inp.value);
// }

// 方式二(配合css实现)
let inp = document.querySelector('input'),
    ball = document.querySelector('.ball'),
    cal = () => ball.style.setProperty('--delay', `-${inp.value}s`);

inp.oninput = cal;
cal();
相关推荐
我是Superman丶17 分钟前
Element UI 表格某行突出悬浮效果
前端·javascript·vue.js
恋猫de小郭17 分钟前
你的代理归我了:AI 大模型恶意中间人攻击,钱包都被转走了
前端·人工智能·ai编程
xiaokuangren_44 分钟前
前端css颜色
前端·css
Huanzhi_Lin1 小时前
关于V8/MajorGC/MinorGC——性能优化
javascript·性能优化·ts·js·v8·新生代·老生代
hoiii1871 小时前
C# 基于 LumiSoft 实现 SIP 客户端方案
前端·c#
anOnion1 小时前
构建无障碍组件之Meter Pattern
前端·html·交互设计
小码哥_常2 小时前
Spring Boot配置diff:解锁配置管理新姿势
前端
小码哥_常2 小时前
告别onActivityResult!Android数据回传的3大痛点与终极解决方案
前端
hhcccchh2 小时前
1.2 CSS 基础选择器、盒模型、flex 布局、grid 布局
前端·css·css3
修己xj2 小时前
Markdown 里写公式,别只知道 LaTeX!试试 HTML 标签,简单到飞起
html