function isScrolledIntoView(el) { var elemTop = el.getBoundingClientRect().top; var elemBottom = el.getBoundingClientRect().bottom; var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight); return isVisible; } $(window).scroll(function (event) { $( ".view_box" ).each(function( index ) { if (isScrolledIntoView(this)) { $(this).parent().addClass('in_view'); } }); });