Skip to main content Accessibility Feedback

The Viewport

isInViewport()

isInViewport() is a helper method I wrote to check if any part of an element is in the viewport. It returns true if any part of the element is in the viewport, and false if it’s not.

var elem = document.querySelector('#some-element');
isInViewport(elem); // Boolean: returns true/false

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.