除夕最炫烟花代码

22 篇文章 0 订阅

一、效果展示:烟花特效

二:代码

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>烟花特效</title>
    <link rel="stylesheet" type="text/css" href="css/normalize.css" />
    <link rel="stylesheet" type="text/css" href="css/htmleaf-demo.css">
</head>
<style>
    #myclock{
        background: #919191;
        color: red;
        text-align: center;
        width: 928px;
        height: 123px;
        font-size:74px;
        font-weight:bold;
        font-family:"microsoft yahei","微软雅黑",serif;
    }
    @-webkit-keyframes reverseRotataZ{
        0%{-webkit-transform: rotateZ(0deg);}
        100%{-webkit-transform: rotateZ(-360deg);}
    }
    @-webkit-keyframes rotataZ{
        0%{-webkit-transform: rotateZ(0deg);}
        100%{-webkit-transform: rotateZ(360deg);}
    }
    #musicControl { position:fixed;right:60px;top:145px;margin-top:0;display:inline-block;z-index:99999999;cursor: pointer}
    #musicControl a { display:inline-block;width:25px;height:25px;overflow:hidden;background:url('/yanhua/img/music.png') no-repeat;background-size:100%;}
    #musicControl a audio{width:100%;height:56px;}
    #musicControl a.stop { background-position:left bottom;}
    #musicControl a.on { background-position:0px 1px;-webkit-animation: reverseRotataZ 1.2s linear infinite;}
    #music_play_filter{width:100%;height:100%;overflow:hidden;position:fixed;top:0;left:0;z-index:99999998;}
</style>
<body onLoad="disptime( )">
<div class="htmleaf-container">
    <header class="htmleaf-header">
        <h1><input id="myclock" type="text"   value="" /></h1>
        <span id="musicControl">
            <a id="mc_play" class="on" onclick="play_music();">
            <audio id="musicfx" loop="loop" autoplay="autoplay">
                <source src="/yanhua/music/mp3.flac" type="audio/mpeg">
            </audio>
            </a>
        </span>
    </header>
</div>
<script>window.jQuery || document.write('<script src="js/jquery-1.11.0.min.js"></script>')</script>
<script type="text/javascript" src="js/jquery.fireworks.js"></script>
<script type="text/javascript">
    $('.htmleaf-container').fireworks({
        sound: false, // sound effect
        opacity: 0.7,
        width: '100%',
        height: '90%'
    });

    function disptime() {
        var time = new Date(); //現在の時間
        var hour = time.getHours();  //時、分、秒
        var minute = time.getMinutes();
        var second = time.getSeconds();
        var year = time.getFullYear();
        var month = time.getMonth()
        var day = time.getDay()

        if (minute < 10) //分は1桁の場合、先頭に0を補足
            minute = "0" + minute;
        if (second < 10) //秒は1桁の場合、先頭に0を補足
            second = "0" + second;
        var time = year + "年" + month + "月" + day + "日" + "  " + hour + ":" + minute + ":" + second;
        $("#myclock").attr("value", time);
        var myTime = setTimeout("disptime(  )", 1000); //使用定时器函数,每隔1秒调用disptime( )函数刷新显示
    }
    function play_music(){
        if ($('#mc_play').hasClass('on')){
            $('#mc_play audio').get(0).pause();
            $('#mc_play').attr('class','stop');
        }else{
            $('#mc_play audio').get(0).play();
            $('#mc_play').attr('class','on');
        }
        $('#music_play_filter').hide();
        event.stopPropagation(); //阻止冒泡
    }
    function just_play(id){
        $('#mc_play audio').get(0).play();
        $('#mc_play').attr('class','on');
        if (typeof(id)!='undefined'){
            $('#music_play_filter').hide();
        }
        event.stopPropagation(); //阻止冒泡
    }
    var play_filter=document.getElementById('music_play_filter');
    play_filter.addEventListener('click', function(){
        just_play(1);
    });
    play_filter.addEventListener('touchstart', function(){
        just_play(1);
    });
    play_filter.addEventListener('touchend', function(){
        just_play(1);
    });
    play_filter.addEventListener('touchmove', function(){
        just_play(1);
    });
    play_filter.addEventListener('mousedown', function(){
        just_play(1);
    });
    play_filter.addEventListener('mouseup', function(){
        just_play(1);
    });
    play_filter.addEventListener('mousemove',function(){
        just_play(1);
    });
</script>
</body>
</html>

三:文件获取

烟花源码,除夕最炫烟花代码-其他文档类资源-CSDN下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
除夕烟花是一种常见的节日庆祝活动,如果你想在网页上实现烟花效果,可以使用HTML5和JavaScript来编写代码。下面是一个简单的示例代码: ```html <!DOCTYPE html> <html> <head> <title>除夕烟花</title> <style> canvas { background-color: black; } </style> </head> <body> <canvas id="fireworksCanvas"></canvas> <script> // 创建画布 var canvas = document.getElementById("fireworksCanvas"); var ctx = canvas.getContext("2d"); // 设置画布大小 canvas.width = window.innerWidth; canvas.height = window.innerHeight; // 定义烟花粒子对象 function Particle(x, y) { this.x = x; this.y = y; this.vx = Math.random() * 10 - 5; this.vy = Math.random() * 10 - 5; this.color = getRandomColor(); this.radius = Math.random() * 3 + 1; this.alpha = 1; } // 更新粒子位置和透明度 Particle.prototype.update = function() { this.x += this.vx; this.y += this.vy; this.alpha -= 0.01; }; // 绘制粒子 Particle.prototype.draw = function() { ctx.beginPath(); ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2); ctx.fillStyle = this.color; ctx.globalAlpha = this.alpha; ctx.fill(); }; // 创建烟花 function createFirework() { var x = Math.random() * canvas.width; var y = canvas.height; var particleCount = 100; var particles = []; for (var i = 0; i < particleCount; i++) { var particle = new Particle(x, y); particles.push(particle); } // 更新和绘制烟花粒子 function updateAndDrawParticles() { particles.forEach(function(particle) { particle.update(); particle.draw(); }); particles = particles.filter(function(particle) { return particle.alpha > 0; }); if (particles.length > 0) { requestAnimationFrame(updateAndDrawParticles); } } updateAndDrawParticles(); } // 随机生成颜色 function getRandomColor() { var letters = "0123456789ABCDEF"; var color = "#"; for (var i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; } // 监听鼠标点击事件,创建烟花 document.addEventListener("click", function(event) { createFirework(); }); </script> </body> </html> ``` 这段代码使用了HTML5的`<canvas>`元素来绘制烟花效果。通过JavaScript创建了一个`Particle`对象来表示烟花粒子,然后在点击页面时创建烟花并更新和绘制粒子的位置和透明度。 希望这个代码能帮到你!如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值