幽灵资源网 Design By www.bzswh.com
最近公司项目中要用到这种类似环形进度条的效果,初始就从0开始动画到100%结束。动画结果始终会停留在100%上,并不会到因为数据的关系停留在一半。
如图
代码如下
demo.html
<!doctype html> <html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>demo</title> <style> .rad-prg{ position: relative; } .rad-con{ position: absolute; z-index: 1; top:0; left: 0; text-align: center; width:90px; height: 90px; padding: 10px; font-family: "microsoft yahei"; } </style> </head> <body> <div class="prg-cont rad-prg" id="indicatorContainer"> <div class="rad-con"> <p>¥4999</p> <p>账户总览</p> </div> </div> <script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.min.js">radialIndicator.js 这是jquery的插件
/* radialIndicator.js v 1.0.0 Author: Sudhanshu Yadav Copyright (c) 2015 Sudhanshu Yadav - ignitersworld.com , released under the MIT license. Demo on: ignitersworld.com/lab/radialIndicator.html */ ;(function ($, window, document) { "use strict"; //circumfence and quart value to start bar from top var circ = Math.PI * 2, quart = Math.PI / 2; //function to convert hex to rgb function hexToRgb(hex) { // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF") var shorthandRegex = /^#"").reverse(), i = 0, lastHashReplaced = 0; //changes hash with numbers for (var ln = output.length; i < ln; i++) { if (!numRev.length) break; if (output[i] == "#") { lastHashReplaced = i; output[i] = numRev.shift(); } } //add overflowing numbers before prefix output.splice(lastHashReplaced+1, output.lastIndexOf('#') - lastHashReplaced, numRev.reverse().join("")); return output.reverse().join(''); } } //circle bar class function Indicator(container, indOption) { indOption = indOption || {}; indOption = merge({}, radialIndicator.defaults, indOption); this.indOption = indOption; //create a queryselector if a selector string is passed in container if (typeof container == "string") container = document.querySelector(container); //get the first element if container is a node list if (container.length) container = container[0]; this.container = container; //create a canvas element var canElm = document.createElement("canvas"); container.appendChild(canElm); this.canElm = canElm; // dom object where drawing will happen this.ctx = canElm.getContext('2d'); //get 2d canvas context //add intial value this.current_value = indOption.initValue || indOption.minValue || 0; } Indicator.prototype = { constructor: radialIndicator, init: function () { var indOption = this.indOption, canElm = this.canElm, ctx = this.ctx, dim = (indOption.radius + indOption.barWidth) * 2, //elm width and height center = dim / 2; //center point in both x and y axis //create a formatter function this.formatter = typeof indOption.format == "function" "object") { var range = Object.keys(curColor); for (var i = 1, ln = range.length; i < ln; i++) { var bottomVal = range[i - 1], topVal = range[i], bottomColor = curColor[bottomVal], topColor = curColor[topVal], newColor = val == bottomVal "round"; ctx.beginPath(); ctx.arc(center, center, indOption.radius, -(quart), ((circ) * perVal / 100) - quart, false); ctx.stroke(); //add percentage text if (indOption.displayNumber) { var cFont = ctx.font.split(' '), weight = indOption.fontWeight, fontSize = indOption.fontSize || (dim / (this.maxLength - (Math.floor(this.maxLength*1.4/4)-1))); cFont = indOption.fontFamily || cFont[cFont.length - 1]; ctx.fillStyle = indOption.fontColor || curColor; ctx.font = weight +" "+ fontSize + "px " + cFont; ctx.textAlign = "center"; ctx.textBaseline = 'middle'; ctx.fillText(dispVal, center, center); } return this; }, //animate progressbar to the value animate: function (val) { var indOption = this.indOption, counter = this.current_value || indOption.minValue, self = this, incBy = Math.ceil((indOption.maxValue - indOption.minValue) / (indOption.frameNum || (indOption.percentage "#ccc", 50 : '#333', 100: '#000'} format: null, //format indicator numbers, can be a # formator ex (##,###.##) or a function frameTime: 10, //miliseconds to move from one frame to another frameNum: null, //Defines numbers of frame in indicator, defaults to 100 when showing percentage and 500 for other values fontColor: null, //font color fontFamily: null, //defines font family fontWeight: 'bold', //defines font weight fontSize : null, //define the font size of indicator number interpolate: true, //interpolate color between ranges percentage: false, //show percentage of value displayNumber: true, //display indicator number roundCorner: false, //have round corner in filled bar minValue: 0, //minimum value maxValue: 100, //maximum value initValue: 0 //define initial value of indicator }; window.radialIndicator = radialIndicator; //add as a jquery plugin if ($) { $.fn.radialIndicator = function (options) { return this.each(function () { var newPCObj = radialIndicator(this, options); $.data(this, 'radialIndicator', newPCObj); }); }; } }(window.jQuery, window, document, void 0));以上所述是小编给大家介绍的JS实现环形进度条(从0到100%)效果 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
标签:
js环形进度条
幽灵资源网 Design By www.bzswh.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
幽灵资源网 Design By www.bzswh.com
暂无评论...
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。