HTML代码烟花大全
<!DOCTYPE html> <html> <head> <title>烟花大全</title> <style> body{ background-color:#000; } .firework{ position: absolute; border-radius: 50%; background-color: yellow; animation: shoot 1s ease-out; } @keyframes shoot{ from{ top: 100%; } to{ top: -100px; } } .firework::after{ position: absolute; content: ''; top: 0; left: 0; right: 0; bottom: 0; margin: auto; border-radius: 50%; background-color: red; animation: explode 0.5s ease-out; } @keyframes explode{ from{ transform: scale(0); } to{ transform: scale(2); opacity: 0; } } .firework:nth-child(2){ animation-delay: 0.5s; } .firework:nth-child(3){ animation-delay: 1s; } .firework:nth-child(4){ animation-delay: 1.5s; } .firework:nth-child(5){ animation-delay: 2s; } .firework:nth-child(6){ animation-delay: 2.5s; } </style> </head> <body> <script> for(var i=0; i<6; i++){ var div = document.createElement('div'); div.className = 'firework'; div.style.left = Math.floor(Math.random()*100) + 'vw'; div.style.animationDelay = Math.floor(Math.random()*5) + 's'; document.body.appendChild(div); } </script> </body> </html>
该代码实现了在黑色背景上播放多个烟花的效果。使用伪类实现烟花爆炸效果,使用JavaScript动态创建多个烟花元素,并随机分布和延迟播放。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。