canvas載入效果程式碼例項
本章節分享一段程式碼例項,它利用canvas實現了載入效果。
不知道怎麼描述效果,直接看程式碼演示:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> #canvas { box-shadow: 5px 5px 5px #ccc; } </style> </head> <body> <canvas id="canvas"></canvas> <button>開始動畫</button> <script> var canvas = document.getElementById("canvas"); canvas.width = 800; canvas.height = 600; var btn = document.getElementsByTagName("button")[0]; function loading() { var num = 0; var x = canvas.width / 2; var y = canvas.height / 2; var ctx = canvas.getContext("2d"); var arc_increment = 0; ctx.lineWidth = 3; var timer; ctx.clearRect(0, 0, canvas.width, canvas.height); function draw() { ctx.strokeStyle = '#176785'; ctx.beginPath(); ctx.arc(x, y, 100, (0.5 + arc_increment - 0.02) * Math.PI, (0.5 + arc_increment) * Math.PI); ctx.stroke(); ctx.closePath(); var color = ctx.createLinearGradient(x + 50, y + 100, x + 50, y - 100); color.addColorStop(0, "#499989"); color.addColorStop(1, "#176785"); ctx.fillStyle = color; ctx.beginPath(); ctx.arc(x, y, 100, (0.5 - arc_increment / 2) * Math.PI, (0.5 + arc_increment / 2) * Math.PI); ctx.closePath(); ctx.fill(); ctx.font = "50px Arial"; ctx.fillStyle = "#fff"; ctx.textAlign = "center"; ctx.textBaseline = "middle"; ctx.beginPath(); ctx.fillText(num, x, y); ctx.closePath(); arc_increment += 0.02; num += 1; if (num > 100) { clearInterval(timer); } } timer = setInterval(draw, 100); } btn.addEventListener("click", loading); </script> </body> </html>
相關文章
- 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
- canvas實現的藍色雨滴效果程式碼例項Canvas
- canvas實現的彈力小球效果程式碼例項Canvas
- canvas刮刮樂程式碼例項Canvas
- canvas實現的七巧板效果程式碼例項Canvas
- canvas實現的動態心形效果程式碼例項Canvas
- canvas實現的圓形鐘錶效果程式碼例項Canvas
- canvas實現的簡單畫板效果程式碼例項Canvas
- canvas實現文字線性漸變效果程式碼例項Canvas
- 密碼框輸入提示效果程式碼例項密碼
- input密碼輸入提示效果程式碼例項密碼
- canvas畫圖程式碼例項Canvas
- canvas小遊戲程式碼例項Canvas遊戲
- canvas實現的賽貝爾曲線效果程式碼例項Canvas
- canvas實現的小球四壁碰撞效果程式碼例項Canvas