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>
相關文章
- 實現漫天飛雪的動畫效果動畫
- 利用html5實現的飛雪效果程式碼例項HTML
- canvas畫布效果程式碼Canvas
- canvas火焰效果程式碼例項Canvas
- canvas字母雨效果程式碼例項Canvas
- canvas載入效果程式碼例項Canvas
- canvas擺動效果程式碼例項Canvas
- canvas水位進度效果程式碼例項Canvas
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas田字格效果程式碼例項Canvas
- canvas繪製圓環效果程式碼例項Canvas
- canvas螞蟻線效果程式碼例項Canvas
- css紙飛機效果程式碼例項CSS
- canvas模擬彈幕效果程式碼例項Canvas
- canvas繪製箭頭效果程式碼例項Canvas
- canvas繪製夜空小屋效果程式碼例項Canvas
- canvas流星劃過星空效果程式碼例項Canvas
- canvas繪製鐘錶效果程式碼例項Canvas
- canvas繪製橢圓效果程式碼例項Canvas
- canvas實現的驗證碼效果程式碼例項Canvas
- canvas繪製魚吃豆效果程式碼例項Canvas
- canvas實現煙花燃放效果程式碼例項Canvas
- canvas繪製雪花飄落效果程式碼例項Canvas
- canvas實現的鋸齒效果程式碼例項Canvas
- canvas實現的鐘表效果程式碼例項Canvas
- 利用canvas實現的驗證碼效果程式碼例項Canvas
- Canvas實現放大鏡效果完整案例分析(附程式碼)Canvas
- canvas實現的雪花飄落效果程式碼例項Canvas
- canvas實現的藍色雨滴效果程式碼例項Canvas
- canvas實現的彈力小球效果程式碼例項Canvas
- canvas實現的七巧板效果程式碼例項Canvas
- canvas實現的動態心形效果程式碼例項Canvas
- canvas實現的圓形鐘錶效果程式碼例項Canvas
- canvas實現的簡單畫板效果程式碼例項Canvas
- canvas實現文字線性漸變效果程式碼例項Canvas
- canvas實現的賽貝爾曲線效果程式碼例項Canvas
- canvas實現的小球四壁碰撞效果程式碼例項Canvas