File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,22 @@ const SpeedTest = {
5353
5454 // Initialize gauge
5555 ProgressGauge . init ( ) ;
56+
57+ // Scrollspy: update active nav link based on which section is in view
58+ const sections = document . querySelectorAll ( '#wrapper > section[id]' ) ;
59+ const navLinks = document . querySelectorAll ( '#sidebar nav a' ) ;
60+
61+ const observer = new IntersectionObserver ( entries => {
62+ entries . forEach ( entry => {
63+ if ( entry . isIntersecting ) {
64+ navLinks . forEach ( link => {
65+ link . classList . toggle ( 'active' , link . getAttribute ( 'href' ) === '#' + entry . target . id ) ;
66+ } ) ;
67+ }
68+ } ) ;
69+ } , { rootMargin : '-45% 0px -45% 0px' , threshold : 0 } ) ;
70+
71+ sections . forEach ( section => observer . observe ( section ) ) ;
5672 } ,
5773
5874 onPrivacyChange ( ) {
You can’t perform that action at this time.
0 commit comments