Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

animated progress bar cdn

// animated progress bar html code 
 <svg class="radial-progress" data-percentage="82" viewBox="0 0 80 80">
  <circle class="incomplete" cx="40" cy="40" r="35"></circle>
  <circle class="complete" cx="40" cy="40" r="35" style="stroke-dashoffset: 39.58406743523136;"></circle>
  <text class="percentage" x="50%" y="57%" transform="matrix(0, 1, -1, 0, 80, 0)">82%</text>
 </svg>

// anitmated progress bar css code
svg.radial-progress {
  height: auto;
  max-width: 200px;
  padding: 1em;
  transform: rotate(-90deg);
  width: 100%;
}

svg.radial-progress circle {
  fill: rgba(0,0,0,0);
  stroke: #fff;
  stroke-dashoffset: 219.91148575129; 
  stroke-width: 10;
}

svg.radial-progress circle.incomplete { opacity: 0.25; }

svg.radial-progress circle.complete { stroke-dasharray: 219.91148575129; }

svg.radial-progress text {
  fill: #fff;
  text-anchor: middle;
}

//animated progress bar js code
$('svg.radial-progress').each(function( index, value ) { 
  $(this).find($('circle.complete')).removeAttr( 'style' );
});


$(window).scroll(function(){
  $('svg.radial-progress').each(function( index, value ) { 
    // If svg.radial-progress is approximately 25% vertically into the window when scrolling from the top or the bottom
    if ( 
        $(window).scrollTop() > $(this).offset().top - ($(window).height() * 0.75) &&
        $(window).scrollTop() < $(this).offset().top + $(this).height() - ($(window).height() * 0.25)
    ) {
        // Get percentage of progress
        percent = $(value).data('percentage');
        // Get radius of the svg's circle.complete
        radius = $(this).find($('circle.complete')).attr('r');
        // Get circumference (2πr)
        circumference = 2 * Math.PI * radius;
        // Get stroke-dashoffset value based on the percentage of the circumference
        strokeDashOffset = circumference - ((percent * circumference) / 100);
        // Transition progress for 1.25 seconds
        $(this).find($('circle.complete')).animate({'stroke-dashoffset': strokeDashOffset}, 1250);
    }
  });
}).trigger('scroll');


Comment

PREVIOUS NEXT
Code Example
Javascript :: put validation on the cell number in angular 
Javascript :: using fetch hook 
Javascript :: clone copy a table in servicenow 
Javascript :: comment creer des switch en react js 
Javascript :: key html 
Javascript :: JS call url many times 
Javascript :: get nearest to user location js 
Javascript :: html tag in string 
Javascript :: translate from json string to object c# 
Javascript :: react native asyncstorage mergeItem example 
Javascript :: javascript react store component as function 
Javascript :: vscode redirect back 
Javascript :: VM360:1 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 
Javascript :: how to check null and undefined 
Javascript :: 5.1.3. Boolean Expressions&para; 
Javascript :: playwrigth await browser 
Javascript :: useHistory: useNavigate if you install v6 or more than react-router-dom": ^6.2.1 
Javascript :: javascript keyup original src element 
Javascript :: function expession js 
Javascript :: Square Space | jquery 
Javascript :: counter random interval 
Javascript :: Example of Private Class Methods and Accessors in es12 
Javascript :: react get query params from url 
Javascript :: populating selectfield from json file 
Javascript :: Replace all ocourrences in JS 
Javascript :: how to get csrf token javascript document query selector 
Javascript :: react native delay input 
Javascript :: convert path string to url encoding javascript 
Javascript :: datatables show loading 
Javascript :: javascript display block div 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =