Update nav-bar on page-ready as well as on scroll (rather than only on scroll event)

This commit is contained in:
Tobias Mühlberger 2022-01-03 21:18:24 +01:00
parent bc0b69d726
commit 5457a260c3

View file

@ -1,13 +1,6 @@
"use strict";
(function ($) {
jQuery(document).ready(function () {
// change navbar style on scroll
// ==================================================
// When the user scrolls down 80px from the top of the document, resize the navbar's padding and the logo's font size
// $.onscroll = function() {scrollFunction()};
$(document).scroll(function () {
const updateNavBar = () => {
if ($(document).scrollTop() > 40) {
$('#top-navbar').removeClass('initial-navbar');
$('#top-navbar').addClass('final-navbar shadow');
@ -36,6 +29,17 @@
$('#logo').attr("src", logoURL);
}
}
};
(function ($) {
jQuery(document).ready(function () {
// change navbar style on scroll
// ==================================================
// When the user scrolls down 80px from the top of the document, resize the navbar's padding and the logo's font size
// $.onscroll = function() {scrollFunction()};
$(document).scroll(function () {
updateNavBar();
});
// Creates a click handler to collapse the navigation when
@ -46,6 +50,8 @@
$('.navbar-collapse').collapse('hide');
});
}
updateNavBar();
});
})(jQuery);