CSS3 粒子效果

  • css3粒子效果,粒子飘飞效果,觉得挺不错的效果。请注意,此为CSS3代码,IE浏览器看不到效果,请使用IE9或火狐浏览器,或Chrome浏览器。
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>接触角测定仪</title>
</head>
<body>
<style type="text/css">
#topcanvas{position:absolute;background:#fff;z-index:-7;width:300px;height:300px;}
</style>
<script type="text/javascript">
    function $(id){
        return typeof id === "string" ? document.getElementById(id) : id;
        }
        (function (window, undefined) {
            if (window.ZHJ) {
                return;
            }
            // }
            var ZHJ = window.ZHJ = {};
            //粒子效果
            ZHJ.drawPartical = {
                drawFunction : function(ctx,r){//构造粒子模板--公用函数
                    ctx.save();
                    ctx.beginPath();
                    ctx.moveTo(r,0);
                    for(var i=0;i<10;i++){
                        ctx.rotate(Math.PI/Math.random()*20);
                        ctx.lineTo(r,0);
                    }
                    ctx.closePath();
                    ctx.fill();
                    ctx.restore();
                },
                drawImplement : function(){//粒子效果--产生粒子,定制密度,颜色
                    setInterval(function(){
                        var topcCanvas = $('topcanvas');
                        var ctx = topcCanvas.getContext('2d');
                        ctx.fillStyle = '#fff';//画布颜色
                        ctx.fillRect(0,0,300,150);//填充区域的大小为200*150
                        ctx.save();
                        ctx.beginPath();
                        for(var j=1;j<100;j++){//生成粒子密度
                            ctx.save();
                            ctx.fillStyle = '#ccc';//粒子颜色
                            ctx.translate(300-Math.floor(Math.random()*300),75-Math.floor(Math.random()*150));
                            ZHJ.drawPartical.drawFunction(ctx,Math.floor(Math.random()*4));//粒子生成
                            ctx.restore();
                        }
                        ctx.restore();
                    },100);
                }
            };
            ZHJ.drawPartical.drawImplement();//粒子--页面执行处
        })(window);
    </script>
    <canvas id="topcanvas"></canvas>
</body>
</html>

 

转载于:https://www.cnblogs.com/youtianxia/p/3911869.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值