Skip to content

Commit 8251bd5

Browse files
committed
Nav Toggle v.1
1 parent 9f98808 commit 8251bd5

File tree

16 files changed

+489
-271
lines changed

16 files changed

+489
-271
lines changed

.idea/workspace.xml

Lines changed: 243 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_config.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
title: Sleek # your site title
22
author: GitHub User
3-
email: your-email@domain.com # email be used for form submission
3+
email: your-email@domain.com # email for form submission, you also have to change it in _js/scripts.js
44
description: > # this means to ignore newlines until "baseurl:"
55
Write an awesome description for your new site here. You can edit this
66
line in _config.yml. It will appear in your document head meta (for
@@ -31,10 +31,13 @@ exclude:
3131
- README.md
3232
- node_modules
3333
- package.json
34+
- package-lock.json
3435
- Gemfile
3536
- Gemfile.lock
3637
- vendor
3738
- npm-debug.log
39+
- gulpfile.js
40+
- sleek.png
3841

3942
include: ['_pages']
4043
permalink: /:title/

_includes/critical.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_includes/header.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77
</div>
88
</a>
99
<nav class="header__links">
10-
<a class="header__link" href="{{ '/' | relative_url }}" itemprop="url"><span itemprop="name">Home</span></a>
11-
<a class="header__link" href="{{ '/about' | relative_url }}" itemprop="url"><span itemprop="name">About</span></a>
12-
<a class="header__link" href="{{ '/contact' | relative_url }}" itemprop="url"><span itemprop="name">Contact</span></a>
10+
<div class="container header__links-wrapper">
11+
<a class="header__link" href="{{ '/' | relative_url }}" itemprop="url"><span itemprop="name">Home</span></a>
12+
<a class="header__link" href="{{ '/about' | relative_url }}" itemprop="url"><span itemprop="name">About</span></a>
13+
<a class="header__link" href="{{ '/contact' | relative_url }}" itemprop="url">
14+
<span itemprop="name">Contact</span>
15+
</a>
16+
</div>
1317
</nav>
1418
<div class="header__toggle">
1519
<span></span>

_js/scripts.js

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/*eslint-env jquery*/
2-
// log what was clicked (only for dev)
3-
// $( document ).click( function( e ) {
4-
// console.log( e.target );
5-
// } );
62

73
// Jquery & Velocity JS included in GULP
84
$( document ).ready( function() {
95

6+
toggleMobileNav();
107
ShowHideNav();
118
formCheck();
129

@@ -17,18 +14,78 @@ $( document ).keyup( function( e ) {
1714
e.keyCode === 27 ? removeModal() : null;
1815
} );
1916

17+
$( window ).resize( function() {
18+
$( ".header" ).removeClass( "hide-nav" ); // Ensure nav will be shown on resize
19+
$( ".header__links" ).removeAttr( "style" ); // If mobile nav was collapsed, make sure it's show on DESK
20+
$( ".header__overlay" ).remove();
21+
} );
22+
23+
// Toggle Mobile Navigation
24+
function toggleMobileNav() {
25+
$( ".header__toggle" ).click( function() {
26+
27+
if ( $( ".header__links" ).hasClass( "js--open" ) ) {
28+
hideMobileNav();
29+
}
30+
else {
31+
openMobileNav();
32+
}
33+
} );
34+
35+
$( ".header__overlay" ).click( function() {
36+
hideMobileNav();
37+
} );
38+
}
39+
40+
function openMobileNav() {
41+
$( ".header__links" ).velocity( "slideDown", {
42+
duration: 300,
43+
easing: "ease-out",
44+
display: "block",
45+
visibility: "visible",
46+
begin: function() {
47+
$( ".header__toggle" ).addClass( "--open" );
48+
$( "body" ).append( "<div class='header__overlay'></div>" );
49+
},
50+
progress: function () {
51+
$( ".header__overlay" ).addClass( "--open" );
52+
},
53+
complete: function() {
54+
$( this ).addClass( "js--open" );
55+
}
56+
} );
57+
}
58+
59+
function hideMobileNav() {
60+
$( ".header__overlay" ).remove();
61+
$( ".header__links" ).velocity( "slideUp", {
62+
duration: 300,
63+
easing: "ease-out",
64+
display: "none",
65+
visibility: "hidden",
66+
begin: function() {
67+
$( ".header__toggle" ).removeClass( "--open" );
68+
},
69+
progress: function () {
70+
$( ".header__overlay" ).removeClass( "--open" );
71+
},
72+
complete: function() {
73+
$( this ).removeClass( "js--open" );
74+
$( ".header__toggle, .header__overlay" ).removeClass( "--open" );
75+
}
76+
} );
77+
}
2078

2179
// SHOW/HIDE NAV
2280
function ShowHideNav() {
2381
var previousScroll = 0, // previous scroll position
2482
$header = $( ".header" ), // just storing header in a variable
2583
navHeight = $header.outerHeight(), // nav height
26-
detachPoint = 650, // after scroll past this nav will be hidden
84+
detachPoint = 576 + 60, // after scroll past this nav will be hidden
2785
hideShowOffset = 6; // scroll value after which nav will be shown/hidden
2886

2987
$( window ).scroll( function() {
3088
var wW = 1024;
31-
3289
// if window width is more than 1024px start show/hide nav
3390
if ( $( window ).width() >= wW ) {
3491
if ( !$header.hasClass( "fixed" ) ) {
@@ -41,26 +98,27 @@ function ShowHideNav() {
4198
// if scrolled past detach point -> show nav
4299
if ( currentScroll > detachPoint ) {
43100
if ( !$header.hasClass( "fix-nav" ) ) {
44-
$header.addClass( "fix-nav" );
45-
}
101+
$header.addClass( "fix-nav" );
102+
}
46103
}
104+
47105
if ( scrollDifference >= hideShowOffset ) {
48106
if ( currentScroll > previousScroll ) {
49107

50108
// scroll down -> hide nav
51109
if ( !$header.hasClass( "hide-nav" ) ) {
52-
$header.addClass( "hide-nav" );
110+
$header.addClass( "hide-nav" );
53111
}
54112
} else {
55113

56114
// scroll up -> show nav
57115
if ( $header.hasClass( "hide-nav" ) ) {
58-
$( $header ).removeClass( "hide-nav" );
59-
}
116+
$( $header ).removeClass( "hide-nav" );
117+
}
60118
}
61119
}
62-
} else {
63-
120+
}
121+
else {
64122
// at the top
65123
if ( currentScroll <= 0 ) {
66124
$header.removeClass( "hide-nav show-nav" );
@@ -83,10 +141,6 @@ $( $header ).removeClass( "hide-nav" );
83141
} );
84142
}
85143

86-
// Ensure nav will be shown on resize
87-
$( window ).resize( function() {
88-
$( ".header" ).removeClass( "hide-nav" );
89-
} );
90144

91145
function openModal() {
92146
$( "body" ).css( "overflow", "hidden" );

0 commit comments

Comments
 (0)