Skip to content

Commit ff70acf

Browse files
committed
Fix scroll glitch using TOC
1 parent fa0d5a4 commit ff70acf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

toc.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,18 @@ window.addEventListener( 'resize', recalculatePositions, false );
100100

101101
// 3. Make the links work
102102
toc.addEventListener( 'click', function ( event ) {
103-
var target = event.target,
104-
item;
103+
var target = event.target;
104+
var href, item;
105105
while ( target && target.nodeName !== 'A' ) {
106106
target = target.parentNode;
107107
}
108108
if ( target ) {
109-
item = index[ target.getAttribute( 'href' ) ];
109+
href = target.getAttribute( 'href' );
110+
item = index[ href ];
110111
}
111112
if ( item ) {
113+
event.preventDefault();
114+
history.pushState( null, document.title, href );
112115
scrollTo( item.top );
113116
}
114117
});

0 commit comments

Comments
 (0)