i'm trying to make a function that toggles a current class for each navbar item when its corresponding section is scrolled into view. anyone got any idea what i'm doing wrong?
$(function () {
$(document).scroll(function () {
var $home = $(".home");
var $about = $(".about");
var $contact = $(".contact");
var $home_section = $("#home");
var $about_section = $("#about");
var $contact_section = $("#contact");
$home.toggleClass('current', $(this).scrollTop() > $home_section.top());
$about.toggleClass('current', $(this).scrollTop() > $about_section.top());
$contact.toggleClass('current', $(this).scrollTop() > $contact_section.top());
});
});