Saturday, August 30, 2025
HomeLanguagesJavascriptHow to write a program that will return true if the bottom...

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:

  • Here we will first create a function that will be called whenever you use the scroll.
  • Now we will check whether the bottom is visible each time when the function is called using the window height and the scrolled window height.
  • And we stored the result inside the flag variable and printed it onto the console.

Example:

HTML




<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:

 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7013 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS