1 Star 1 Fork 0

静静的灰尘/circle-progress

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Circle Progress

Responsive, accessible, animated, stylable with CSS circular progress bar available as plain (vanilla) JavaScript and jQuery plugin.

See examples or go to the project site

Getting Started

As plain JavaScript

Download the minified production version

In your web page:

<div class="progress"></div>

<script src="dist/circle-progress.min.js"></script>

<script>
    new CircleProgress('.progress');
</script>

As jQuery plugin

Download the minified jQuery production version

In your web page:

<div class="progress"></div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="dist/jquery.circle-progress.min.js"></script>

<script>
  jQuery(function($) {
    $('.progress').circleProgress();
  });
</script>

A note about jQuery file

jQuery version of Circle Progress is built on top of plain JavaScript version. It uses jQuery Widget Factory. Two files are available: one that contains the Widget Factory code, and one that doesn't.

  1. You can use the smaller jquery.circle-progress.bare.min.js, if you have already included the jQuery Widget Factory or another native jQuery widget in your page.
  2. Otherwise you must use jquery.circle-progress.min.js, which includes the jQuery Widget Factory code.

Usage

Initiate Circle Progress

Plain JavaScript

const circleProgress = new CircleProgress(element, options, doc);

where

element is HTML element or selector to be converted into a progress circle (required),

options - object map of options (optional),

doc - the document we are acting upon (optional).

jQuery

$('.progress').circleProgress(options);

where options is object map of options (optional).

Options

You can customize Circle Progress with these options by either passing options object at initiation, or setting them later, e. g.:

In plain js

Set options as properties on a CircleProgress instance:

circleProgress.max = 100;
circleProgress.value = 20;

or using the chainable attr method by passing it option key and value:

circleProgress
	.attr('max', 100)
	.attr('value', 20);

or options object

circleProgress.attr({
	max: 100,
	value: 20,
});

In jQuery

$('.progress').circleProgress('value', 20);

or

$('.progress').circleProgress({
	max: 100,
	value: 20,
});

All available options

Option Type Default Description
value Number Indeterminate Current value
min Number 0 Minimum value
max Number 1 Maximum value
startAngle Number 0 Starting angle in degrees. Angle of 0 points straight up. Direction depends on clockwise.
clockwise Boolean true Whether to rotate clockwise (true) or anti-clockwise (false)
constrain Boolean true Whether the value should be constrained between min and max. If true, values over max will be truncated to max and values under min will be set to min.
indeterminateText String '?' Text to display as the value when it is indeterminate
textFormat String or Function 'horizontal' Text layout for value, min, max.
You can pass either one of the possible keywords:
horizontal - value/max
vertical - value is shown over max
percent - value%
value - only value is shown
valueOnCircle - the value is painted on top of the filled region on the circle
none - no text is shown.
Alternatively you can provide your own function, which will be called each time progress is updated with value and max as arguments and is expected to return a string to insert in the center of the progress circle
animation String 'easeInOutCubic' Animation easing function. One of linear, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuadr, easeOutQuadr, easeInOutQuadr or none
animationDuration Number 600 Animation duration in milliseconds

To customize widget's appearance, you can style its underlying SVG elements with CSS. The elements are:

Class Description
circle-progress The svg image. You can use this selector to scale the widget. E. g.: .circle-progress {width: 200px; height: auto;}
circle-progress-circle The entire circle (SVG circle element)
circle-progress-value The arc representing currently filled progress (SVG path element)
circle-progress-text Text controlled by textFormat option (SVG text element)
circle-progress-text-value Current value text (SVG tspan element). Appears only for textFormat values of horizontal, vertical, valueOnCircle
circle-progress-text-max Maximum value text (SVG tspan element). Appears only for textFormat values of horizontal, vertical, valueOnCircle

You can use any SVG presentation attributes on these elements. Particularly useful are: fill, stroke, stroke-width, stroke-linecap properties. (See examples)

The default options are stored in CircleProgress.defaults or jQuery.fn.circleProgress.defaults. The two are references to the same object. You can override them, so that all instances will be created with the overridden options.

Browser Support

Chrome, Firefox, Safari, Edge and IE 11 are supported.

License

© 2018 Tigran Sargsyan

Licensed under (the MIT License)

The MIT License (MIT) Copyright (c) 2018 Tigran Sargsyan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Responsive, accessible, animated, stylable with CSS circular progress bar available as plain (vanilla) JS and jQuery plugin. 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/League2st/circle-progress.git
git@gitee.com:League2st/circle-progress.git
League2st
circle-progress
circle-progress
master

搜索帮助