CSS3 粒子效果

來源:互聯網
上載者:User

標籤:style   blog   http   color   java   使用   os   io   

  • css3粒子效果,粒子飄飛效果,覺得挺不錯的效果。請注意,此為CSS3代碼,IE瀏覽器看不到效果,請使用IE9或Firefox瀏覽器,或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>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.