首頁  >  文章  >  web前端  >  使用html5製作loading圖表的範例_html5教學技巧

使用html5製作loading圖表的範例_html5教學技巧

WBOY
WBOY原創
2016-05-16 15:48:011577瀏覽


複製程式碼
程式碼如下:









<script><br /> var Loading = function (canvas, options) {<br /> this.canvas = document.getElementById(canvas);<br /> this.options = options;<br /> };</script>

}; >

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();
}());

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn