foreach,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style type="text/css">
body {
height: 1000px
}
#spacer {
position: relative;
top: 500px;
width: 300px;
height: 100px;
background-color: #FF0066;
}
#status {
position: fixed;
top: 0px;
width: 300px;
height: 30px;
background-color: #66FFFF;
}
</style>
<script type="text/javascript">
$(document).ready(function (){
$(window).scroll(function () {
var spac = $(window).height();
var pos = Math.round($('#spacer').position().top) ;
var scroll = $(window).scrollTop()
$('#status').text('h = '+spac+' p= '+pos + ' s = '+scroll + ' show = ' + (spac+scroll > pos));
});
});
</script>
</head>
<body>
<div id='status'>
</div>
<div id='spacer'>
</div>
<script>
</script>
</body>
</html>