```<!doctype html>
<!-- 文本行 -->
<!--烟花容器-->
<br>
// 有延迟的字符<br>
const 行 = [<br>
{ id: “line1”, text: “happy”; },<br>
{ id:“第 2 行”,文本:“新”; },<br>
{ id:“第 3 行”,文本:“年份”; }<br>
];</p>
<div class="高亮"><pre class="高亮明文"><code>let 延迟 = 0;
函数 shotfirework(x, y, 回调) {
const firework = document.createelement('div');
firework.classname = '烟花';
firework.style.left = `${x}px`;
firework.style.top = `${y}px`;
firework.style.background = `hsl(${math.random() * 360}, 100%, 50%)`;
firework.style.boxshadow = `0 0 10px hsl(${math.random() * 360}, 100%, 50%)`;
document.body.appendchild(烟花);
settimeout(() => {
烟花.remove();
回调(x,y);
}, 1000); // 烟花持续时间
}
函数explodefirework(x, y) {
for (令 i = 0; i spark.remove(), 1200); // 火花持续时间
}
}
函数revealcharacter(字符,容器,延迟){
const span = document.createelement('span');
span.classname = 'char';
span.textcontent = char;
span.style.animationdelay = `${delay}s`;
span.style.color = `hsl(${math.random() * 360},
100%, 70%)`;
容器.appendchild(span);
}
lines.foreach((行,索引) => {
const 容器 = document.getelementbyid(line.id);
line.text.split('').foreach((char, i) => {
const x = window.innerwidth / 2 i * 50 - (line.text.length * 25);
const y = window.innerheight;
settimeout(() => {
shotfirework(x, y, () => {
爆炸烟火(x,y);
revealcharacter(字符, 容器, 0);
});
}, 延迟 * 1000);
延迟 = 1; // 每个角色烟花之间的延迟
});
延迟 = 1; // 线路之间的额外延迟
});
</code></pre></div>
<p>
以上就是使用 html css 和 js 的新年快乐动画的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号