Skip to content

Commit 5516793

Browse files
committed
[ADD] new bootstrap 5 compatible JS
1 parent 0ccce36 commit 5516793

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

js/scripts.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*!
2+
* Start Bootstrap - Grayscale v7.0.5 (https://startbootstrap.com/theme/grayscale)
3+
* Copyright 2013-2022 Start Bootstrap
4+
* Licensed under MIT (https://github.com/StartBootstrap/startbootstrap-grayscale/blob/master/LICENSE)
5+
*/
6+
//
7+
// Scripts
8+
//
9+
10+
window.addEventListener('DOMContentLoaded', event => {
11+
12+
// Navbar shrink function
13+
var navbarShrink = function () {
14+
const navbarCollapsible = document.body.querySelector('#mainNav');
15+
if (!navbarCollapsible) {
16+
return;
17+
}
18+
if (window.scrollY === 0) {
19+
navbarCollapsible.classList.remove('navbar-shrink')
20+
} else {
21+
navbarCollapsible.classList.add('navbar-shrink')
22+
}
23+
24+
};
25+
26+
// Shrink the navbar
27+
navbarShrink();
28+
29+
// Shrink the navbar when page is scrolled
30+
document.addEventListener('scroll', navbarShrink);
31+
32+
// Activate Bootstrap scrollspy on the main nav element
33+
const mainNav = document.body.querySelector('#mainNav');
34+
if (mainNav) {
35+
new bootstrap.ScrollSpy(document.body, {
36+
target: '#mainNav',
37+
offset: 74,
38+
});
39+
};
40+
41+
// Collapse responsive navbar when toggler is visible
42+
const navbarToggler = document.body.querySelector('.navbar-toggler');
43+
const responsiveNavItems = [].slice.call(
44+
document.querySelectorAll('#navbarResponsive .nav-link')
45+
);
46+
responsiveNavItems.map(function (responsiveNavItem) {
47+
responsiveNavItem.addEventListener('click', () => {
48+
if (window.getComputedStyle(navbarToggler).display !== 'none') {
49+
navbarToggler.click();
50+
}
51+
});
52+
});
53+
54+
});

0 commit comments

Comments
 (0)