Skip to content

Commit 8ce10e9

Browse files
Fixed body scrolling below navigation overlay (css and js).
1 parent bde4449 commit 8ce10e9

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

_sass/style.scss

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
overflow-x: hidden;
1313
}
1414

15+
.no-scroll {
16+
overflow: hidden;
17+
}
18+
1519
a {
1620
color: #035E9A;
1721
text-decoration: none !important;

static/js/site.js

+23-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@ var hamburgerBar = $(".navigation__hamburger-bar");
33
var navigationOverlay = $(".navigation__overlay");
44
var buttonCloseContainer = $(".navigation__button-close-container");
55
var navigationButtonClose = $(".navigation__button-close");
6+
var scrollPosition = 0;
7+
var scrollBarWidth = 0;
8+
69

710
$(document).ready(function () {
811
buttonOpenContainer.on("click", openNav);
912
navigationButtonClose.on("click", closeNav);
1013
});
1114

15+
function setActiveLink() {
16+
var currentURL = window.location.href;
17+
$('.navigation__link, .footer__link').each(function () {
18+
if (this.href === currentURL) {
19+
$(this).addClass('active');
20+
}
21+
});
22+
}
23+
1224
function openNav() {
25+
scrollPosition = $(window).scrollTop();
26+
scrollBarWidth = (window.innerWidth - $(window).width());
27+
$("body").addClass("no-scroll");
28+
// To prevent content from jumping when scrollbar disappears.
29+
$(window).scrollTop(scrollPosition);
30+
$("body").css("padding-right", scrollBarWidth + "px");
1331
buttonOpenContainer.css("pointer-events", "none");
1432
buttonOpenContainer.toggle(500, showCloseButton);
1533
hamburgerBar.css("background-color", "transparent");
@@ -18,6 +36,9 @@ function openNav() {
1836

1937
/* Close when someone clicks on the "x" symbol inside the overlay */
2038
function closeNav() {
39+
$("body").removeClass("no-scroll");
40+
// To stop content jerking left-right when scrollbar is restored.
41+
$("body").css("padding-right", "");
2142
hamburgerBar.css("background-color", "#ffffff");
2243
navigationOverlay.css("width", "0%");
2344
buttonOpenContainer.css("display", "inline");
@@ -65,11 +86,5 @@ for (let i=0; i<elements.length; i++) {
6586
// footer on page load.
6687
$(setActiveLink());
6788

68-
function setActiveLink() {
69-
var currentURL = window.location.href;
70-
$('.navigation__link, .footer__link').each(function () {
71-
if (this.href === currentURL) {
72-
$(this).addClass('active');
73-
}
74-
});
75-
}
89+
90+

0 commit comments

Comments
 (0)