i know there is already topics about this problem but all solutions didn't worked for me.
i want my menu to be fixed on top of my page when user is scrolling.
i found a script and adapted it for my needs :
var win = $(document.body);
var fxel = $('#stickynav');
var eloffset = $('#stickynav').offset().top;
console.log(win.scrollTop());
win.scroll(function() {
if (eloffset < win.scrollTop()) {
console.log('fixed');
fxel.addClass("fixed");
} else {
console.log(eloffset + ' != ' + win.scrollTop());
fxel.removeClass("fixed");
}
});
it's working on firefox and IE8 but not in chrome, win.scrollTop() is always returning 0.
i tried everything win = $(document)
, $(window)
and $('body, html')
and it's always returning 0 or nothing.
Can somebody help me?