@@ -3,13 +3,31 @@ var hamburgerBar = $(".navigation__hamburger-bar");
3
3
var navigationOverlay = $ ( ".navigation__overlay" ) ;
4
4
var buttonCloseContainer = $ ( ".navigation__button-close-container" ) ;
5
5
var navigationButtonClose = $ ( ".navigation__button-close" ) ;
6
+ var scrollPosition = 0 ;
7
+ var scrollBarWidth = 0 ;
8
+
6
9
7
10
$ ( document ) . ready ( function ( ) {
8
11
buttonOpenContainer . on ( "click" , openNav ) ;
9
12
navigationButtonClose . on ( "click" , closeNav ) ;
10
13
} ) ;
11
14
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
+
12
24
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" ) ;
13
31
buttonOpenContainer . css ( "pointer-events" , "none" ) ;
14
32
buttonOpenContainer . toggle ( 500 , showCloseButton ) ;
15
33
hamburgerBar . css ( "background-color" , "transparent" ) ;
@@ -18,6 +36,9 @@ function openNav() {
18
36
19
37
/* Close when someone clicks on the "x" symbol inside the overlay */
20
38
function closeNav ( ) {
39
+ $ ( "body" ) . removeClass ( "no-scroll" ) ;
40
+ // To stop content jerking left-right when scrollbar is restored.
41
+ $ ( "body" ) . css ( "padding-right" , "" ) ;
21
42
hamburgerBar . css ( "background-color" , "#ffffff" ) ;
22
43
navigationOverlay . css ( "width" , "0%" ) ;
23
44
buttonOpenContainer . css ( "display" , "inline" ) ;
@@ -65,11 +86,5 @@ for (let i=0; i<elements.length; i++) {
65
86
// footer on page load.
66
87
$ ( setActiveLink ( ) ) ;
67
88
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