I have a circular progress bar that animates when the page loads, but I want it to animate when the user scrolls down to it, as it will be in the middle of the page. Right now if the page loads, the user does not see the animation.
So essentially, the animation should be paused until the user scrolls down to a certain point, once the bar is in view, the animation starts.
I used this jquery plugin https://www.jqueryscript.net/loading/jQuery-Plugin-SVG-Progress-Circle.html
function makesvg(percentage, inner_text = "") {
var abs_percentage = Math.abs(percentage).toString();
var percentage_str = percentage.toString();
var classes = ""
if (percentage < 0) {
classes = "danger-stroke circle-chart__circle--negative";
} else if (percentage > 0 && percentage <= 30) {
classes = "warning-stroke";
} else {
classes = "success-stroke";
}
var svg = '<svg class="circle-chart" viewbox="0 0 33.83098862 33.83098862"
xmlns = "http://www.w3.org/2000/svg" > ' +
'<circle class="circle-chart__background" cx="16.9" cy="16.9" r="15.9" / >
' +
'<circle class="circle-chart__circle ' + classes + '"' +
'stroke-dasharray="' + abs_percentage + ',100" cx="16.9" cy="16.9"
r = "15.9" / > ' +
'<g class="circle-chart__info">' +
' <text style="color:#fff;" class="circle-chart__percent" x="17.9"
y = "15.5" > '+percentage_str+' % < /text>';
if (inner_text) {
svg += '<text class="circle-chart__subline" x="16.91549431"
y = "22" > '+inner_text+' < /text>'
}
svg += ' </g></svg>';
return svg
}
(function($) {
$.fn.circlechart = function() {
this.each(function() {
var percentage = $(this).data("percentage");
var inner_text = $(this).text();
var inner_text2 = $(this).text();
$(this).html(makesvg(percentage, inner_text));
});
return this;
};
});
$('.circlechart').circlechart(); // Initialization