w3resource

JavaScript: Return true if the bottom of the page is visible, false otherwise

JavaScript fundamental (ES6 Syntax): Exercise-261 with Solution

Check Page Bottom Visible

Write a JavaScript program that returns true if the page bottom is visible, false otherwise.

  • Use scrollY, scrollHeight and clientHeight to determine if the bottom of the page is visible.

Sample Solution:

JavaScript Code:

//#Source https://bit.ly/2neWfJ2 
// Define a function 'bottomVisible' to check if the bottom of the page is visible
const bottomVisible = () =>
  // Check if the sum of the client height of the document element and the scroll Y offset
  // is greater than or equal to the maximum of the scroll height of the document element
  // and the client height of the document element
  document.documentElement.clientHeight + window.scrollY >=
  (document.documentElement.scrollHeight || document.documentElement.clientHeight);

// Check if the bottom of the page is visible
console.log(bottomVisible());

Output:

true

Flowchart:

flowchart: Return true if the bottom of the page is visible, false otherwise.

Live Demo:

See the Pen javascript-basic-exercise-261-1 by w3resource (@w3resource) on CodePen.


For more Practice: Solve these Related Problems:

  • Write a JavaScript program that returns true if the bottom of the page is visible in the viewport, using scroll position.
  • Write a JavaScript function that checks document.documentElement.scrollHeight against window.innerHeight and scrollY.
  • Write a JavaScript program that listens for scroll events and logs when the user reaches the bottom of the page.
  • Write a JavaScript function that calculates the remaining scroll distance and determines if the page bottom is in view.

Go to:


PREV : Binomial Coefficient.
NEXT : Encode String to Base-64.

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.