File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,21 @@ <h1>A story about getting lost.</h1>
55
55
56
56
< script >
57
57
58
+ const nav = document . querySelector ( '#main' ) ;
59
+ const navTop = nav . offsetTop ;
60
+
61
+ function isFixed ( ) {
62
+ if ( navTop >= window . scrollY ) {
63
+ document . body . classList . remove ( 'fixed' ) ;
64
+ document . body . style . paddingTop = 0 ;
65
+ } else {
66
+ document . body . classList . add ( 'fixed' ) ;
67
+ document . body . style . paddingTop = nav . offsetHeight + 'px' ;
68
+ }
69
+ }
70
+
71
+ document . addEventListener ( 'scroll' , isFixed ) ;
72
+
58
73
</ script >
59
74
60
75
</ body >
Original file line number Diff line number Diff line change 46
46
transition : all 0.5s ;
47
47
position : relative;
48
48
z-index : 1 ;
49
+
50
+ }
51
+ .fixed nav {
52
+ position : fixed;
49
53
}
50
54
51
55
nav ul {
@@ -72,6 +76,10 @@ li.logo {
72
76
font-size : 30px ;
73
77
}
74
78
79
+ .fixed .logo {
80
+ max-width : 500px ;
81
+ }
82
+
75
83
li .logo a {
76
84
color : black;
77
85
}
You can’t perform that action at this time.
0 commit comments