File tree 3 files changed +26
-21
lines changed
3 files changed +26
-21
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ module.exports = function(config) {
8
8
config . addPassthroughCopy ( 'src/img' ) ;
9
9
config . addPassthroughCopy ( 'src/manifest.json' ) ;
10
10
11
- config . addPlugin ( pluginTOC , { tags : [ 'h2' ] } ) ;
11
+ config . addPlugin ( pluginTOC , { tags : [ 'h2' , 'h3' , 'h4' ] } ) ;
12
12
config . addPlugin ( syntaxHighlight ) ;
13
13
config . addPlugin ( imageOptimizations ) ;
14
14
config . addPlugin ( eleventyNavigationPlugin ) ;
Original file line number Diff line number Diff line change 1
1
const observer = new IntersectionObserver ( entries => {
2
- entries . forEach ( entry => {
3
- const id = entry . target . getAttribute ( 'id' ) ;
4
-
5
- if ( entry . intersectionRatio > 0 ) {
6
- if ( document . querySelector ( `.pageNav li.is-active` ) ) {
7
- document . querySelector ( `.pageNav li.is-active` ) . classList . remove ( 'is-active' ) ;
8
- }
9
-
10
- document . querySelector ( `.pageNav a[href="#${ id } "]` ) . parentElement . classList . add ( 'is-active' ) ;
2
+ const intersectingEntries = entries . filter ( e => e . isIntersecting ) ;
3
+ for ( const entry of intersectingEntries ) {
4
+ const previouslyActive = document . querySelector ( '.pageNav a.is-active' ) ;
5
+ if ( previouslyActive ) {
6
+ previouslyActive . classList . remove ( 'is-active' ) ;
11
7
}
12
- } )
8
+
9
+ const id = entry . target . getAttribute ( 'id' )
10
+ const newActive = document . querySelector ( `.pageNav a[href="#${ id } "]` ) ;
11
+ newActive . classList . add ( 'is-active' ) ;
12
+ newActive . scrollIntoView ( { block : 'nearest' } ) ;
13
+ }
13
14
} , { rootMargin : `0% 0% -90% 0%` }
14
15
) ;
15
16
16
- //track h2's with an id
17
+ //track headings with an id
17
18
if ( document . querySelector ( '.pageNav' ) ) {
18
- document . querySelectorAll ( 'h2 [id]' ) . forEach ( ( section ) => {
19
- observer . observe ( section ) ;
20
- } ) ;
21
- }
19
+ for ( const heading of document . querySelectorAll ( ':is(h2,h3,h4) [id]' ) ) {
20
+ observer . observe ( heading )
21
+ }
22
+ }
Original file line number Diff line number Diff line change @@ -337,10 +337,11 @@ nav{
337
337
padding-left : 0 ;
338
338
border-left : 1px solid var (--light-grey );
339
339
font-size : .9em ;
340
-
340
+ margin : 0 ;
341
341
}
342
342
.pageNav a {
343
343
padding-left : 1em ;
344
+ border-left : 3px solid transparent;
344
345
display : inline-block;
345
346
}
346
347
nav ul {
@@ -358,7 +359,7 @@ nav a:hover{
358
359
nav li {
359
360
margin-bottom : 1em ;
360
361
}
361
- nav .is-active > a {
362
+ . primaryNav .is-active > a {
362
363
font-weight : bold;
363
364
color : # 000 ;
364
365
}
@@ -368,14 +369,17 @@ nav li ul{
368
369
}
369
370
370
371
.toc .is-active {
371
- border-left : 3 px solid var (--wpt-navy );
372
+ border-left-color : var (--wpt-navy );
372
373
color : var (--wpt-navy );
373
374
}
374
375
@media (min-width : 68em ) {
375
376
.toc {
377
+ --top-offset : 1em ;
376
378
position : sticky;
377
- top : 1em ;
378
- padding-top : .5em ;
379
+ top : var (--top-offset );
380
+ margin-top : 1.5em ;
381
+ max-height : calc (100vh - 2 * var (--top-offset ));
382
+ overflow-y : auto;
379
383
}
380
384
}
381
385
.toc li {
You can’t perform that action at this time.
0 commit comments