File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5555 hook . afterEach ( function ( html ) {
5656 return html + footer ;
5757 } ) ;
58-
59- hook . ready ( function ( ) {
60- // true = show debug log
61- let dd = false ;
62- let TARGET_QUERY = 'id' ;
63- let SCROLL_DELAY = 2000 ; // in milisecond
64- let location = window . location ;
65-
66- dd && console . log ( 'custom scroll plugin called!' ) ;
67- let currentUrlWithoutHash = new URL (
68- location . origin + location . pathname + location . search + location . hash . substring ( 1 )
69- ) ;
70- let urlQueryParam = currentUrlWithoutHash . searchParams ;
71- let isUrlHasIdQuery = urlQueryParam . has ( TARGET_QUERY ) ;
72- if ( isUrlHasIdQuery ) {
73- dd && console . log ( 'url has id, will scroll to element' ) ;
74- let urlId = urlQueryParam . get ( TARGET_QUERY ) ;
75- // run delayed, to make sure everything loaded
76- setTimeout ( function ( ) {
77- dd && console . log ( 'will scroll now!' ) ;
78- try {
79- document . querySelector ( '#' + urlId ) . scrollIntoView ( ) ;
80- } catch ( e ) {
81- dd && console . log ( 'custom scroll failed' , e ) ;
82- }
83- } , SCROLL_DELAY ) ;
84- }
85- } ) ;
8658 } ,
8759 ] ,
8860 } ;
Original file line number Diff line number Diff line change 22 function create ( ) {
33 return ( hook ) => {
44 const TARGET_QUERY = 'id' ;
5- const SCROLL_DELAY = 500 ;
5+ const SCROLL_DELAY = 650 ;
66
77 hook . ready ( function ( ) {
88 if ( ! location . hash . includes ( '?' ) ) return ;
You can’t perform that action at this time.
0 commit comments