$(window).on('scroll', function() {
var fromTop = $(document).scrollTop(),
$items = $('.item'),
allItems = [],
$currentItem;
allItems = $items.filter(function() {
return $(this).offset().top < fromTop;
});
$currentItem = allItems.eq(allItems.length - 1);
$items.removeClass('active');
$currentItem.addClass('active');
});
Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the "@" symbol from your selectors in order to make them work again.