File tree Expand file tree Collapse file tree 5 files changed +50
-2
lines changed
Expand file tree Collapse file tree 5 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,6 @@ html[mode=dark] {
4848
4949:root {
5050 font-size : 16px ;
51- scroll-behavior : smooth ;
5251}
5352
5453body {
Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ $(function() {
1212 } ) ;
1313
1414 $ ( "#back-to-top" ) . click ( ( ) => {
15- $ ( "body,html" ) . scrollTop ( 0 ) ;
15+ $ ( "body,html" ) . animate ( {
16+ scrollTop : 0
17+ } , 800 ) ;
1618 return false ;
1719 } ) ;
1820} ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ Safari doesn't support CSS `scroll-behavior: smooth`,
3+ so here is a compatible sollution for all browser to smooth scrolling
4+
5+ See: <https://css-tricks.com/snippets/jquery/smooth-scrolling/>
6+
7+ Warning: It must be called after all `<a>` tags (e.g., the dynamic TOC) are ready.
8+ */
9+
10+ $ ( function ( ) {
11+ $ ( "a[href*='#']" )
12+ . not ( "[href='#']" )
13+ . not ( "[href='#0']" )
14+ . click ( function ( event ) {
15+
16+ if ( location . pathname . replace ( / ^ \/ / , "" ) === this . pathname . replace ( / ^ \/ / , "" )
17+ && location . hostname === this . hostname ) {
18+
19+ var target = $ ( decodeURI ( this . hash ) ) ;
20+
21+ if ( target . length ) {
22+
23+ event . preventDefault ( ) ;
24+
25+ $ ( "html, body" ) . animate ( {
26+ scrollTop : target . offset ( ) . top
27+ } , 800 , function ( ) {
28+ var $target = $ ( target ) ;
29+ $target . focus ( ) ;
30+
31+ if ( $target . is ( ":focus" ) ) { /* Checking if the target was focused */
32+ return false ;
33+ } else {
34+ $target . attr ( "tabindex" , "-1" ) ; /* Adding tabindex for elements not focusable */
35+ $target . focus ( ) ; /* Set focus again */
36+ }
37+ } ) ;
38+ }
39+ }
40+
41+ } ) ; /* click() */
42+ } ) ;
Original file line number Diff line number Diff line change @@ -9,3 +9,5 @@ layout: compress
99-- -
1010
1111{ % include_relative _commons . js % }
12+
13+ { % include_relative _utils / smooth - scroll . js % }
Original file line number Diff line number Diff line change @@ -17,3 +17,6 @@ layout: compress
1717{ % include_relative _utils / img - hyperlink . js % }
1818
1919{ % include_relative _utils / lang - badge . js % }
20+
21+ { % comment % } `smooth-scroll.js` must be called after ToC is ready { % endcomment % }
22+ { % include_relative _utils / smooth - scroll . js % }
You can’t perform that action at this time.
0 commit comments