jQuery(document).ready(function($){ $('body').running(); $(window).bind("scroll",function(){ var top=$(window).scrollTop(); $('.section .graybg').each(function(){ if ($(this).offset().top -top< $(window).height() - 200){ $('.section .graybg').removeClass('selected'); $(this).addClass('selected'); }; }) }); })