I don't undestand why my code doesn't work properly I created a bullet menu on my page who doesn't working properly. The bullets don't correspond to each sections. For example the last bullet don't correspond to the "Contact" section (last section).
Bullet 1 => Home - "Bullet 1" title
Bullet 2 => "Bullet 2" title
Bullet 3 => "Bullet 3" title
Bullet 4 => "Bullet 4" title
When I scroll the page the bullet doesn't correspond and when I click on a bullet that's the same :-(
PS: I can't use $(window) or $('html, body') instead of $('#page') because of the structure of my page.
http://jsfiddle.net/Xroad/FtaL3/2/
I don't undestand why my code doesn't work properly, any idea ?
$(function(){
var sections = [];
var id = false;
var $navbar = $('.navbar');
var $navbara = $('a', $navbar);
$navbara.click(function(e){
$('#page').animate({
scrollTop: $($(this).attr('href')).offset().top
});
});
$navbara.each(function(){
sections.push($($(this).attr('href')));
});
$('#page').scroll(function(e){
var scrollTop = $(this).scrollTop() + ($('#page').height() / 2)
for(var i in sections){
var section = sections[i];
if (scrollTop > section.offset().top) {
scrolled_id = section.attr('id');
}
}
if (scrolled_id !== id) {
id = scrolled_id
$navbara.removeClass('current');
$('a[href="#' + id + '"]', $navbar).addClass('current');
}
});
});