How can i get a percentage of loading?

Hi developer
I’m using a body-html api
but loader api is not contain a file that represent a percentage of loading …

does it exist such a api file or function?

thank’s for rep

1 Like

There is no API function that provides the loading progress information.

1 Like

Just an idea:
You could grab the current dash-offset of the loading circle to calculate the current loading progress in percent. Something like this (just a quick solution):

<script>
const primaryProgressDone = document.getElementById('primary-progress-done');
let loadingProgress = primaryProgressDone.getAttribute("stroke-dashoffset");

const getLoadingProgress = () => {

  const offset = primaryProgressDone.style.strokeDashoffset;

  if(!totalOffset && offset) {
    totalOffset = offset;
  }

  if(totalOffset) {
    progress = Math.round(100 - offset / totalOffset * 100);

    // Log to console
    console.log(progress);
  }

  if(offset == 0 && offset !== "") {
    clearInterval(getPercent);
  }

}

let totalOffset = false;
let progress = false;
let getPercent = setInterval(getLoadingProgress, 100);
</script>

This logs the current progress to the JS console. Hope it helps.

2 Likes