I have a sticky green bar on [this site] [1]. When you go to Chrome, the panel moves up and sticks to the top of the page and remains fixed as you continue to scroll. But I just noticed that this does not work in Firefox or IE. Used javascript below. Does anyone have any idea why it only works in Chrome? (does not work on mobile devices, FYI)
jQuery(function($) {
var docked = false;
var menu = $('.sticky_cta');
var init = menu.offset().top;
$(window).scroll(function() {
if (!docked && (menu.offset().top - $("body").scrollTop() < 50)) {
menu.css({
position : "fixed",
top: 0,
});
docked = true;
}
else if (docked && $("body").scrollTop() <= init) {
menu.css({
position: "relative",
});
docked = false;
}
});
});
[1]:
source
share