Skip to content

Commit

Permalink
fix pageload scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Chimildic committed Mar 27, 2021
1 parent 19b6f68 commit 17990fd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
28 changes: 0 additions & 28 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,6 @@
hook.afterEach(function (html) {
return html + footer;
});

hook.ready(function () {
// true = show debug log
let dd = false;
let TARGET_QUERY = 'id';
let SCROLL_DELAY = 2000; // in milisecond
let location = window.location;

dd && console.log('custom scroll plugin called!');
let currentUrlWithoutHash = new URL(
location.origin + location.pathname + location.search + location.hash.substring(1)
);
let urlQueryParam = currentUrlWithoutHash.searchParams;
let isUrlHasIdQuery = urlQueryParam.has(TARGET_QUERY);
if (isUrlHasIdQuery) {
dd && console.log('url has id, will scroll to element');
let urlId = urlQueryParam.get(TARGET_QUERY);
// run delayed, to make sure everything loaded
setTimeout(function () {
dd && console.log('will scroll now!');
try {
document.querySelector('#' + urlId).scrollIntoView();
} catch (e) {
dd && console.log('custom scroll failed', e);
}
}, SCROLL_DELAY);
}
});
},
],
};
Expand Down
2 changes: 1 addition & 1 deletion docs/script/docsify-fix-pageload-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
function create() {
return (hook) => {
const TARGET_QUERY = 'id';
const SCROLL_DELAY = 500;
const SCROLL_DELAY = 650;

hook.ready(function () {
if (!location.hash.includes('?')) return;
Expand Down

0 comments on commit 17990fd

Please sign in to comment.