I tried to fixed an element on top, when this element touch the top of the window, when the user scroll down. On scroll down everything works (added a class with the fixed position), but when I scroll up doesn't work. but i don't understand why :( i created a jsfiddle with this code: http://jsfiddle.net/8h4knr9r/
$(window).scroll(function () {
var distance = $('#navigation-sections').offset().top;
if ($(window).scrollTop() >= $('#navigation-sections').offset().top) {
$('#navigation-sections').addClass("affix");
} else {
$('#navigation-sections').removeClass("affix");
}
});
thanks