複製程式碼程式碼如下: <br /> var Loading = function (canvas, options) {<br /> this.canvas = document.getElementById(canvas);<br /> this.options = options;<br /> }; }; > Loading.prototype = { 建構子: Loading, show: function () { var canvas = this.canvas, begin = this.options.begin, old🎜> old = this.options .old, lineWidth = this.options.lineWidth, canvasCenter = {x: canvas.width / 2, y: canvas.height / 2}, ctx = canvas. "2d") , color = this.options.color, num = this.options.num,角度= 0, lineCap = this.options.lineCap, CONST_PI = Math.PI * (360 / num) / 180; window.timer = setInterval(function () { ctx.clearRect(0, 0, canvas.width, canvas.height); for ( var i = 0 ; i ctx.beginPath(); ctx.行程風格= 顏色[num - 1 - i]; ctx.lineWidth = 線寬度; ctx.lineCap= lineCap; ctx.moveTo(canvasCenter.x Math.cos(CONST_PI * i 角度) * 開始, canvasCenter.y Math.sin(CONST_PI * i 角度) * 開始); ctx.lineTo(canvasCenter .x Math.cos(CONST_PI * i 角度) * 舊, canvasCenter.y Math.sin(CONST_PI * i 角度) * 舊); ctx.lines(); ctx.closePath (); } angle = CONST_PI; console.log(angle) },50); }, hide: function () {clearInterval(視窗.計時器); } }; (function () { var options = { num : 8, 開始: 20, 舊: 40, lineWidth: 10, ", 顏色: ["rgb(0, 0, 0)", "rgb(20, 20, 20)","rgb(40, 40, 40)", "rgb(60, 60, 60) "," rgb(80, 80, 80)", "rgb(100, 100, 100)", "rgb(120, 120, 120)", "rgb(140, 140, 140)"] } ; var loading = new Loading("canvas", options); loading.show(); }());