Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check whether entire div is viewable for the user

Is there a way to check whether the div is entirely visible to the user? I mean the scroll bar is positioned so that the entire div fits inside the viewport.

like image 565
keepwalking Avatar asked Dec 21 '11 20:12

keepwalking


People also ask

How do I check if a div is visible?

Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.

How do you know if an element is completely visible?

To know whether the element is fully visible in viewport, you will need to check whether top >= 0, and bottom is less than the screen height. In a similar way you can also check for partial visibility, top is less than screen height and bottom >= 0.

How do you know if an element is present in DOM?

contains DOM API, you can check for the presence of any element in the page (currently in the DOM) quite easily: document. body. contains(YOUR_ELEMENT_HERE);


1 Answers

This is exactly what this was created for: http://www.appelsiini.net/projects/viewport

like image 117
Ayman Safadi Avatar answered Sep 18 '22 11:09

Ayman Safadi