烟花代码html
时间: 2023-06-30 22:15:58 浏览: 41
以下是一个简单的烟花效果的 HTML 代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>烟花效果</title>
<style>
body {
background-color: #1c1c1c;
}
#firework {
width: 10px;
height: 10px;
background-color: #f00;
border-radius: 50%;
position: absolute;
animation: explode 1s ease-out;
animation-fill-mode: forwards;
}
@keyframes explode {
0% {
transform: scale(0);
}
50% {
transform: scale(1.5);
opacity: 0.5;
}
100% {
transform: scale(2);
opacity: 0;
}
}
</style>
</head>
<body>
<script>
function createFirework() {
const firework = document.createElement("div");
firework.id = "firework";
firework.style.left = Math.random() * window.innerWidth + "px";
firework.style.top = Math.random() * window.innerHeight + "px";
document.body.appendChild(firework);
setTimeout(() => {
firework.remove();
}, 1000);
}
setInterval(createFirework, 200);
</script>
</body>
</html>
```
这段代码定义了一个名为 `firework` 的 div 元素,并用 CSS 添加了一个动画效果,使其看起来像是烟花爆炸。JavaScript 部分则创建了多个这样的元素,并将它们添加到页面上。通过 setInterval 函数,可以控制创建烟花的速度。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)