jQuery Circular Progress Bar with Percentage

jQuery Circular Progress Bar with Percentage
Code Snippet:Animated on scroll Circle Progress Bar
Author: JAMES M OBRIEN
Published: January 11, 2024
Last Updated: January 22, 2024
Downloads: 11,992
License: MIT
Edit Code online: View on CodePen
Read More

The “Circle Progress” jQuery plugin helps you to build a circular progress bar with a percentage value. The plugin renders an animated circular progress bar with custom size, position, percentage value, and thickness.

How to create jQuery Circular Progress Bar with Percentage

1. In HTML, create a div element with a class name “progressbar” and define its data-animate as false. Similarly, create another div tag inside it with a class name “circle” and set percentage data attribute. The complete HTML structure for the circular progress bar is as follows:

<div class="progressbar" data-animate="false">
   <div class="circle" data-percent="90">
      <div></div>
   </div>
</div>

2. After that, style your circular progress bar with CSS.

.progressbar {
		display: inline-block;
		width: 100px;
		margin: 25px;
	}
	.circle {
		width: 180px;
		height: 180px;
		margin: 0 auto;
		margin-top: 10px;
		display: inline-block;
		position: relative;
		text-align: center;
	}
	.circle:after {
	    width: 120px;
		height: 120px;
		content: "";
		border: 2px solid #fb4f14;
		border-radius: 50%;
		display: block;
		position: absolute;
		top: 30px;
		left: 30px;
	}
	
	.circle canvas {
		vertical-align: middle;
		border: 2px solid #fb4f14;
		border-radius: 50%;
	}
	
	.circle div {
		position: absolute;
		top: 50%;
		left: 50%;
		margin: -20px 0 0 -86px;
		width: 100%;
		text-align: center;
		line-height: 40px;
		font-size: 31px;
		
	}
	.circle strong i {
		font-style: normal;
		font-size: 0.6em;
		font-weight: normal;
	}
	.circle span {
		display: block;
		color: white;
		margin-top: 12px;
	}
	

3. Now, load the jQuery JavaScript library and progress bar plugin in your HTML document.

<!-- jQuery -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<!-- Circle Progress JS -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-circle-progress/1.2.2/circle-progress.min.js'>

4. Finally, initialize the plugin (with the following configurations) in the jQuery document ready function and done.

$(document).ready(function ($) {
		function animateElements() {
			$('.progressbar').each(function () {
				var elementPos = $(this).offset().top;
				var topOfWindow = $(window).scrollTop();
				var percent = $(this).find('.circle').attr('data-percent');
				var percentage = parseInt(percent, 10) / parseInt(100, 10);
				var animate = $(this).data('animate');
				if (elementPos < topOfWindow + $(window).height() - 30 && !animate) {
					$(this).data('animate', true);
					$(this).find('.circle').circleProgress({
						startAngle: -Math.PI / 2,
						value: percent / 100,
						size: 180,
						thickness: 30,
						emptyFill: "rgba(0,0,0, .2)",
						fill: {
							color: '#fb4f14'
						}
					}).on('circle-animation-progress', function (event, progress, stepValue) {
						$(this).find('div').text((stepValue*100).toFixed(1) + "%");
					}).stop();
				}
			});
		}

		// Show animated elements
		animateElements();
		$(window).scroll(animateElements);
		
		
		

	}); //end document ready function

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X