Skip to content

Instantly share code, notes, and snippets.

@elishaukpong
Created May 11, 2020 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elishaukpong/94f35ba84d5f319cabb5358fbee11412 to your computer and use it in GitHub Desktop.
Save elishaukpong/94f35ba84d5f319cabb5358fbee11412 to your computer and use it in GitHub Desktop.
// PRELOADER
var width = 100,
perfData = window.performance.timing, // The PerformanceTiming interface represents timing-related performance information for the given page.
EstimatedTime = -(perfData.loadEventEnd - perfData.navigationStart),
time = parseInt((EstimatedTime / 1000) % 60, 10) * 100;
var PercentageID = $("#percentage"),
start = 0,
end = 100,
durataion = time;
animateValue(PercentageID, start, end, durataion);
function animateValue(id, start, end, duration) {
var range = end - start,
current = start,
increment = end > start ? 1 : -1,
stepTime = Math.abs(Math.floor(duration / range)),
obj = $(id);
var timer = setInterval(function() {
current += increment;
$(obj).text(current);
//obj.innerHTML = current;
if (current == end) {
clearInterval(timer);
}
}, stepTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment