I'm creating an infinite horizontal feed where I want to animate the element when it enters the viewport horizontally. I'm trying waypoint.js for this.
<div id="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
Adding .show to div which will change opacity of div from 0 to 1.
$(function() {
$(".item").each(function(){
$(this).waypoint(function() {
$(this).addClass('show');
}, {
offset: '100%',
horizontal: true
});
});
});
CSS
.item
{
width:500px;
height:250px;
background:red;
color:#fff;
display:inline-block;
opacity:.2;
}
.item.show
{
opacity:1;
}
But now the elements would not change their opacity from 0 to 1 when they enter the viewport horizontally. Any idea why? Sorry, I'm really new to javascript and waypoint.