最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

使用html5制作loading图的示例_html5教程技巧

来源:动视网 责编:小采 时间:2020-11-27 15:18:45
文档

使用html5制作loading图的示例_html5教程技巧

使用html5制作loading图的示例_html5教程技巧:代码如下: var Loading = function (canvas, options) { this.canvas = document.getElementById(canvas); this.options = options; }; Loading.prototype = { constructor: Loading, show:
推荐度:
导读使用html5制作loading图的示例_html5教程技巧:代码如下: var Loading = function (canvas, options) { this.canvas = document.getElementById(canvas); this.options = options; }; Loading.prototype = { constructor: Loading, show:
 代码如下:







var Loading = function (canvas, options) {
this.canvas = document.getElementById(canvas);
this.options = options;
};

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

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



效果图:

文档

使用html5制作loading图的示例_html5教程技巧

使用html5制作loading图的示例_html5教程技巧:代码如下: var Loading = function (canvas, options) { this.canvas = document.getElementById(canvas); this.options = options; }; Loading.prototype = { constructor: Loading, show:
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top