Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

On screen update javascript

I want to have a function that runs on screen update in javascript a while (true) {do something} freezes the entire screen is there a way to do this kind of like this:

<!DOCTYPE html>
<html>
  <body>
    <p id="label">Not Working</p>
    <script>
      var l = document.getElementById("label");
      window.addEventListener("update",function(){
        l.innerHTML = "Is Working";
      });
    </script>
  </body>
</html>

It does not work so is there a way to do this easily???

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can have a function run on the next frame with window.requestAnimationFrame(callback)

<!DOCTYPE html>
<html>

<body>
  <p id="label">Loading</p>
  <script>
    var l = document.getElementById("label");

    function update() {
      l.innerHTML = Date.now();
      window.requestAnimationFrame(update);
    }
    update();
  </script>
</body>

</html>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading