canvas漫天飛雪效果程式碼
分享一段程式碼例項,它利用canvas實現了滿天飛雪效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style type="text/css"> * { margin: 0; padding: 0; } html, body { height: 100%; } #myCanvas { background-color: #87CEEB; } </style> </head> <body> <canvas id="myCanvas" width="1000" height="600"></canvas> <script type="text/javascript"> var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); var practicles = []; for (var count = 0; count < 500; count++) { //迴圈生成500粒 practicles.push({ x: Math.random() * (window.innerWidth), y: Math.random() * (window.innerHeight), vx: Math.random() - 0.5, vy: Math.random() + 0.5, size: Math.random() * 3 + 1, color: "#FFF" }) } function timeUpdate() { context.clearRect(0, 0, window.innerWidth, window.innerHeight); //清除畫布區域 var practicle; for (var count = 0; count < 500; count++) { var practicle = practicles[count]; practicle.x += practicles[count].vx; practicle.y += practicles[count].vy; if (practicle.x < 0) { practicle.x = window.innerWidth } if (practicle.x > window.innerWidth) { practicle.x = 0 } if (practicle.y > window.innerHeight) { practicle.y = 0 } context.beginPath(); context.arc(practicle.x, practicle.y, practicle.size, 0, Math.PI * 2) context.closePath(); context.fillStyle = practicle.color; context.fill(); } } setInterval(timeUpdate, 40); </script> </body> </html>
相關文章
- canvas載入效果程式碼例項Canvas
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- Canvas實現放大鏡效果完整案例分析(附程式碼)Canvas
- canvas矩形拖拽效果Canvas
- canvas小球碰壁效果Canvas
- canvas簽名效果Canvas
- 震驚,canvas文字粒子效果,只需要100行程式碼,簡單易懂。Canvas行程
- canvas蔚藍星空效果Canvas
- canvas繪製流星效果Canvas
- canvas小球擺動效果Canvas
- canvas實現波浪效果Canvas
- 程式碼雨效果
- canvas設定陰影效果Canvas
- canvas圓形時鐘效果Canvas
- canvas簡單畫板效果Canvas
- canvas繪製風車效果Canvas
- canvas動態時鐘效果Canvas
- 分享一個canvas程式碼2Canvas
- 冬奧“雪飛天”銀裝素裹LBW
- canvas環形進度條效果Canvas
- canvas實現 漂亮的下雨效果Canvas
- canvas立體效果的圓環Canvas
- canvas具有漸變效果的矩形Canvas
- canvas水平勻速運動效果Canvas
- Canvas系列之一——濾鏡效果Canvas
- canvas透明度的矩形效果Canvas
- canvas刮刮樂程式碼例項Canvas
- canvas吃豆小遊戲程式碼Canvas遊戲
- canvas繪製扇形程式碼例項Canvas
- jQuery打字機效果程式碼jQuery
- CSS div居中效果程式碼CSS
- svg生成矩形效果程式碼SVG
- 由canvas實現btn效果有感Canvas
- canvas繪製網格射線效果Canvas
- canvas繪製卡通人臉形象效果Canvas
- canvas繪製多個圓圈效果Canvas