JSFiddle - React, Tailwind, and code Playground

by Narayan Prusty

JavaScript

window.addEventListener("scroll", function(){
        var heightOfWindow = window.innerHeight;
        var contentScrolled = window.pageYOffset;
        var bodyHeight = window.document.getElementsByTagName("body")[0].offsetHeight;
        if(bodyHeight - contentScrolled <= heightOfWindow)
       {
           window.document.getElementById("percentage").innerHTML = "100%";
       }
       else
       {
           var total = bodyHeight - heightOfWindow;
           var got = contentScrolled;
           window.document.getElementById("percentage").innerHTML = parseInt((got/total) * 100);
       }
}, false);