$('div p').click(function() { var index = $(this).index(); var scrolltop = $('ul li').eq(index).offset().top; $('html,body').stop(false).animate({ scrollTop: scrolltop }, 200); }) $(window).scroll(function() { var top = $(this).scrollTop() $('ul li').each(function(i) { var h = $(this).offset().top; console.log(top) if(top >= h) { $('p').eq(i).addClass('on').siblings().removeClass('on'); } }) })