I'm using Ascensor.js. I need to detect which div section is visible in window to add animation effects to elements inside that visible div.
For following code,
<div id="ascensorBuilding">
<section>
//floor one content here
</section>
</div>
I'm using my code,
<div id="wrapper">
<div class="section about" id="about">
</div>
<div class="section home" id="Home">
</div>
</div>
It's working well.
And my script to detect which div is visible or appearing in window is ,
$(document).ready(function(){
$.fn.isOnScreen = function(){
var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
bounds.right = bounds.left + this.outerWidth();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
if($('.about').isOnScreen())
{
// element is now visible in the viewport
alert("You can see me");
}
else
{
// element has gone out of viewport
alert("You can not see me more !!!");
}
});
I need to make this work
$('.about').isOnScreen(function(){
alert("You can see me");
});
Whenever .about i.e. <div class="section about" id="about"></div>
appears on screen, animation effects can be added to elements inside .about div