Now you can use the "ob_nm" object properties, presented above.
- Here is a simple example:
<div id="dv1">Div content</div>
<script src="elmposiz.js"></script>
<script>
//create object with the elmPosiz() for #dv1
var ob_dv1 = new elmPosiz('#dv1');
//check if #dv1 is minimum 50% visible in viewport
//shows an alert message with top/left position
var dv1_vi = ob_dv1.in_view ?'Visible in viewport' :'Not 50% visible in viewport';
alert('Top: '+ob_dv1.top+' / Left: '+ob_dv1.left+'\n'+dv1_vi);
</script>
- Another example. We set a function to the "listen" property to check when the Div is not 70% visible in viewport, and shows in console the visible percentage.
<div id="dv1">Div content</div>
<script src="elmposiz.js"></script>
<script>
//create object with the elmPosiz() for #dv1
var ob_dv1 = new elmPosiz('#dv1');
//change minimum percentage to 70% for #dv1 to be considered visible in viewport
ob_dv1.min_visible = 70;
//set a function to the listen property to check #dv1 visibility in viewport,
//and shows in console the visible percentage
ob_dv1.listen = function(){
if(!ob_dv1.in_view) console.log('Elm not 70% in viewport, visible: ', ob_dv1.visibleY);
}
</script>