佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 使用html5制作loading圖的示例

使用html5制作loading圖的示例

熱門(mén)標(biāo)簽:智能手機(jī) 使用U盤(pán)裝系統(tǒng) 檢查注冊(cè)表項(xiàng) 網(wǎng)站建設(shè) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 阿里云 美圖手機(jī) 硅谷的囚徒呼叫中心


復(fù)制代碼
代碼如下:

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<canvas id = "canvas"></canvas></p> <p> <script>
var Loading = function (canvas, options) {
this.canvas = document.getElementById(canvas);
this.options = options;
};</p> <p> Loading.prototype = {
constructor: Loading,
show: function () {
var canvas = this.canvas,
begin = this.options.begin,
old = this.options.old,
lineWidth = this.options.lineWidth,
canvasCenter = {x: canvas.width / 2, y: canvas.height / 2},
ctx = canvas.getContext("2d"),
color = this.options.color,
num = this.options.num,
angle = 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 < num; 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) * begin, canvasCenter.y + Math.sin(CONST_PI * i + angle) * begin);
ctx.lineTo(canvasCenter.x + Math.cos(CONST_PI * i + angle) * old, canvasCenter.y + Math.sin(CONST_PI * i + angle) * old);
ctx.stroke();
ctx.closePath();
}
angle += CONST_PI;
console.log(angle)
},50);
},
hide: function () {
clearInterval(window.timer);
}
};</p> <p> (function () {
var options = {
num : 8,
begin: 20,
old: 40,
lineWidth: 10,
lineCap: "round",
color: ["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();
}());
</script>
</body>
</html>


效果圖:

標(biāo)簽:煙臺(tái) 湘潭 湖北 黃山 懷化 賀州 山南 通遼

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《使用html5制作loading圖的示例》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    柘荣县| 始兴县| 崇文区| 全椒县| 崇州市| 蒙山县| 五台县| 资阳市| 宾阳县| 靖宇县| 化州市| 本溪| 浦城县| 永寿县| 西充县| 杂多县| 蚌埠市| 佛山市| 萨嘎县| 岳普湖县| 广灵县| 全椒县| 陇西县| 康保县| 永仁县| 泸西县| 佛冈县| 龙口市| 南平市| 中超| 茌平县| 富阳市| 中宁县| 临邑县| 高碑店市| 信丰县| 庄浪县| 固阳县| 洪洞县| 吴江市| 宝丰县|