Example: http://www.chartjs.org/
When scrolling down each article shows up when it gets in the view-port of the browser. The css is
#examples article {
-webkit-transition: opacity 200ms ease-in-out;
-ms-transition: opacity 200ms ease-in-out;
-moz-transition: opacity 200ms ease-in-out;
-o-transition: opacity 200ms ease-in-out;
transition: opacity 200ms ease-in-out;
position: relative;
margin-top: 20px;
clear: both;
}
I tried this css but it does not work. Is there some javascript that works together with the css? How can I achieve this kind of scroll->fadeIn effect?
Mohammeds answer does not take into account any absolutely positioned images... we should use offset instead of position
$(window).scroll(function () {
/* Check the location of each desired element */
$('.article').each(function (i) {
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, fade it it */
if (bottom_of_window > bottom_of_object) {
$(this).animate({
'opacity': '1'
}, 500);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With