用Html写一个烟花代码
时间: 2023-03-15 07:11:32 浏览: 758
我可以用以下HTML代码来创建一个烟花效果:<html>
<head>
<title>烟花特效</title>
<style type="text/css">
body {
background-color: #FFF;
overflow: hidden;
}#fireworks {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}#fireworks div {
position: absolute;
background: url(firework.gif);
width: 2px;
height: 2px;
}</style>
</head><body>
<div id="fireworks"></div>
<script type="text/javascript">
//烟花特效
var fw = document.getElementById('fireworks');
for (i=0; i<100; i++) {
createFirework(Math.random()*fw.offsetWidth, Math.random()*fw.offsetHeight);
}function createFirework(x,y) {
var d = document.createElement('div');
d.style.left = x+'px';
d.style.top = y+'px';
fw.appendChild(d);
setTimeout(function() {
fw.removeChild(d);
}, 2000);
}
</script>
</body>
</html>
阅读全文