File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 33< head >
44 < meta charset ="UTF-8 ">
55 < title > Sticky Nav</ title >
6- < link rel ="stylesheet " href ="style-START .css ">
6+ < link rel ="stylesheet " href ="style.css ">
77</ head >
88< body >
99
@@ -55,7 +55,24 @@ <h1>A story about getting lost.</h1>
5555
5656< script >
5757
58+ const nav = document . querySelector ( '#main' ) ;
59+ const topOfNav = nav . offsetTop ;
60+
61+ function fixNav ( ) {
62+ console . log ( topOfNav , window . scrollY , nav . offsetHeight ) ;
63+ if ( window . scrollY >= topOfNav ) {
64+ document . body . style . paddingTop = `${ nav . offsetHeight } px` ;
65+ document . body . classList . add ( 'fixed-nav' ) ;
66+ //causes it to be janky (no nav in dom) offset amt on body
67+ } else {
68+ document . body . style . paddingTop = 0 ;
69+ document . body . classList . remove ( 'fixed-nav' ) ;
70+
71+ }
72+ }
73+
74+ window . addEventListener ( 'scroll' , fixNav ) ;
5875</ script >
5976
6077</ body >
61- </ html >
78+ </ html >
Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ body {
2323 transition : transform 0.5s ;
2424}
2525
26+ .fixed-nav .site-wrap {
27+ transform : scale (1 );
28+ }
29+
2630header {
2731 text-align : center;
2832 height : 50vh ;
4751 position : relative;
4852 z-index : 1 ;
4953}
54+ .fixed-nav nav {
55+ position : fixed;
56+ box-shadow : 0 5px rgba (0 , 0 , 0 , 0.1 );
57+ }
5058
5159nav ul {
5260 margin : 0 ;
@@ -64,14 +72,18 @@ nav li {
6472}
6573
6674li .logo {
67- max-width : 0 ;
75+ max-width : 0 ;/*because transitions*/
6876 overflow : hidden;
6977 background : white;
7078 transition : all .5s ;
7179 font-weight : 600 ;
7280 font-size : 30px ;
7381}
7482
83+ .fixed-nav li .logo {
84+ max-width : 500px ; /*because transitions*/
85+ }
86+
7587li .logo a {
7688 color : black;
7789}
You can’t perform that action at this time.
0 commit comments