/* * @author: pikaqiu * @date: 2020-09-21 21:46:51 * @lasteditors: pikaqiu * @lastedittime: 2020-09-21 22:51:18 */ let progress = function (init) { this.init(init) }; progress.prototype = { init: function (init) { this.el = init.el;//元素id let cvselement = document.getelementbyid(this.el),//获取元素 ctx = cvselement.getcontext("2d"),//获取画笔 width = cvselement.width,//元素宽度 height = cvselement.height,//元素高度 degactive = 0,//动态线条 timer = null;//定时器 //停止时的角度 init.deg > 0 && init.deg <= 100 ? this.deg = init.deg : this.deg = 100; //线宽 init.linewidth !== undefined ? this.linewidth = init.linewidth : this.linewidth = 20; //判断宽高较小者 this.wh = width > height ? height : width; //设置圆的半径,默认为宽高较小者 init.circleradius > 0 && init.circleradius <= this.wh / 2 - this.linewidth / 2 ? this.circleradius = init.circleradius : this.circleradius = this.wh / 2 - this.linewidth / 2; //绘制线的背景颜色 // init.linebgcolor !==undefined? // this.linebgcolor = init.linebgcolor:this.linebgcolor='#ccc'; //绘制线的颜色 init.linecolor !== undefined ? this.linecolor = init.linecolor : this.linecolor = '#009ee5'; //绘制文字颜色 init.textcolor !== undefined ? this.textcolor = init.textcolor : this.textcolor = '#009ee5'; //绘制文字大小 init.fontsize !== undefined ? this.fontsize = init.fontsize : this.fontsize = parseint(this.circleradius / 2); //执行时间 this.timer = init.timer; //清除锯齿 if (window.devicepixelratio) { cvselement.style.width = width + "px"; cvselement.style.height = height + "px"; cvselement.height = height * window.devicepixelratio; cvselement.width = width * window.devicepixelratio; ctx.scale(window.devicepixelratio, window.devicepixelratio); } //设置线宽 ctx.linewidth = this.linewidth; //启动定时器 timer = setinterval(function () { ctx.clearrect(0, 0, width, height);//清除画布 ctx.beginpath();//开始绘制底圆 ctx.arc(width / 2, height / 2, this.circleradius, 1, 8); ctx.strokestyle = 'rgba(255, 255, 255, 0.3)'; ctx.stroke(); ctx.beginpath();//开始绘制动态圆 ctx.arc(width / 2, height / 2, this.circleradius, -math.pi / 2, degactive * math.pi / 180 - math.pi / 2); ctx.strokestyle = this.linecolor; ctx.stroke(); let txt = (parseint(degactive * 100 / 360) + "%");//获取百分比 ctx.font = this.fontsize + "px simhei"; let w = ctx.measuretext(txt).width;//获取文本宽度 let h = this.fontsize / 2; ctx.fillstyle = this.textcolor; ctx.filltext(txt, width / 2 - w / 2, height / 2 + h / 2); if (degactive >= this.deg / 100 * 360) {//停止定时器 window.clearinterval(timer); timer = null; flag = true; index_banner.slidenext(); } degactive++; }.bind(this), this.timer); } };