Open In App

How to write a program that will return true if the bottom of the page is visible in JavaScript ?

The task is to return true if the bottom of the page is visible. We can achieve this by simply using the height of the window and the height of the scrolled window.

Approach:



Example:




<h1 style="margin-bottom: 1000px; color:green">DSA</h1>
<script>
    window.onload = function() {
        window.onscroll = function() {
      
            let flag =
            document.documentElement.clientHeight + window.scrollY >=
                (document.documentElement.scrollHeight ||
                document.documentElement.clientHeight);
      
            console.log(flag);
            console.log("GFG scrolled ");
      
        };
    };
</script>

Output:



 

Article Tags :