Skip to content
Related Articles

Related Articles

Improve Article
How to write a program that will return true if the bottom of the page is visible in JavaScript ?
  • Last Updated : 16 Apr, 2021

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.

HTML




<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" 
          content="IE=edge">
    <meta name="viewport" 
          content="width=device-width, 
                   initial-scale=1.0">
    <title>Bottom Visible Javascript</title>
</head>
  
<body>
    <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 scrrolled ");
  
            };
        };
    </script>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :