I have this piece of code, which displays ALL the elements with the same class whenever the first one appears on the screen. What I really wanted to do is to show each element separately whenever it appears on the screen, not all of them in the same time. I hope I explained it clear enough.
Here is the html:
<div class="scrollfx">ELEMENT</div>
<div class="scrollfx">ELEMENT</div>
css:
body {
height:1600px;
}
.scrollfx {
width: 100%;
height: 150px;
background:blue;
position: relative;
top: 50px;
font-size:4em;
margin-top:500px;
filter: opacity(0);
}
.scrollfx.fadein {
filter:opacity(1);
transition: all 2.5s ease;
}
jquery:
$(document).scroll(function () {
var el = $('.scrollfx');
var bottom = el.offset().top + el.outerHeight(true);
var y = $(this).scrollTop();
$('.scrollfx').each(function () {
if (y = bottom) {
$(this).addClass('fadein');
}
});
});