Rumah >hujung hadapan web >Tutorial H5 >Contoh penggunaan html5 untuk membuat loading diagram_html5 kemahiran tutorial
var Memuatkan = fungsi (kanvas, pilihan) {
this.canvas = document.getElementById(kanvas);
this.options = pilihan;
};
Loading.prototype = {
constructor: Loading,
show: function () {
var canvas = this.canvas,
begin = this.options.begin,
old = this.options .lama,
lineWidth = this.options.lineWidth,
canvasCenter = {x: canvas.width / 2, y: canvas.height / 2},
ctx = canvas.getContext("2d") ,
warna = this.options.color,
num = this.options.num,
sudut = 0,
lineCap = this.options.lineCap,
CONST_PI = Math.PI * (360 / num) / 180;
window.timer = setInterval(function () {
ctx.clearRect(0, 0, canvas.width, canvas.height);
untuk (var i = 0 ; i < bilangan i = 1) {
ctx.beginPath();
ctx.strokeStyle = color[num - 1 - i];
ctx.lineWidth = lineWidth;
ctx. lineCap= lineCap;
ctx.moveTo(canvasCenter.x Math.cos(CONST_PI * i angle) * mula, canvasCenter.y Math.sin(CONST_PI * i angle) * begin);
ctx.lineTo(canvasCenter .x Math.cos(CONST_PI * i sudut) * lama, canvasCenter.y Math.sin(CONST_PI * i sudut) * lama);
ctx.stroke();
ctx.closePath();
}
sudut = CONST_PI;
console.log(sudut)
},50);
},
sorok: fungsi () {
clearInterval(window.timer);
}
};
(fungsi () {
var options = {
nombor : 8,
mula: 20,
lama: 40,
lineWidth: 10,
lineCap: "bulat",
warna: ["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("kanvas", pilihan);
loading.show();
}());