Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

element in view?

Status
Not open for further replies.

shades44

Programmer
Jun 14, 2004
25
CA
Hi does anyone know a quick way to find out if an html element is in view or not depending on the scrolled position of the page?
 
well if you know its id, something like this should work.
Code:
<html>
<script>
function checkV()
{
if (document.getElementById('test').offsetTop > (document.body.scrollTop+document.body.clientHeight))
	{alert('not visible');}
else
	{alert('visible');}
}
</script>
<body onscroll='checkV()'>
<BR><BR><BR><BR><BR><BR><BR><BR>
  <BR><BR><BR><BR><BR><BR><BR>
    <BR><BR><BR><BR><BR><BR>
      <BR><BR><BR><BR><BR>
	<BR><BR><BR><BR>
	  <BR><BR><BR>
	    <BR><BR>
	      <BR>
	<div id='test'>foo</div>
</body>
</html>

hope that helps.

"Whether you think that you can, or that you can't, you are usually right." - Henry Ford
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top