this code is working in Firefox but not in Chrome v.23.
When I trace the code in debugger everything works fine but Chrome doesn’t change class. Any ideas?
$(document).scroll(function () {
$('a.nav').each(function () {
var divTop = $('#' + this.title).offset().top;
var distance = divTop - $("html").scrollTop();
if (distance > 210 && distance < 255) {
$('a.active').removeClass('active');
$(this).addClass('active');
}
});
});
The problem is targeting $(“html”) for scrolltop.
See this SO thread: jQuery scrollTop() doesn't seem to work in Safari or Chrome (Windows)
See the second answer for details on what’s actually going on with your scenario, i.e. try using $(‘body’)
Either of the first two solutions should work for you, though.