Skip to content

Commit

Permalink
Revert "Add smooth scrolling to scroll offset fix."
Browse files Browse the repository at this point in the history
This reverts commit 05ab036.
  • Loading branch information
paulhibbitts committed Oct 11, 2024
1 parent 05ab036 commit 610f22a
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1215,38 +1215,24 @@
return; // Exit if basePath is present
}

let TARGET_QUERY = 'id';
let SCROLL_DELAY = 500; // in milliseconds
let location = window.location;
let TARGET_QUERY = 'id'
let SCROLL_DELAY = 1000 // in milisecond
let location = window.location

// Build the current URL without the hash
let currentUrlWithoutHash = new URL(
location.origin + location.pathname +
location.search + location.hash.substring(1)
);

// Get the search parameters from the URL
let urlQueryParam = currentUrlWithoutHash.searchParams;
let isUrlHasIdQuery = urlQueryParam.has(TARGET_QUERY);

// Check if the URL contains the 'id' query parameter
if (isUrlHasIdQuery) {
let urlId = urlQueryParam.get(TARGET_QUERY);

// Delay the scrolling to ensure everything is loaded
setTimeout(function () {
try {
let targetElement = document.querySelector('#' + urlId);
if (targetElement) {
// Scroll to the element with smooth behavior
targetElement.scrollIntoView({
behavior: 'smooth', // Enables smooth scrolling
block: 'start', // Aligns the top of the element to the top of the viewport
});
}
} catch (e) {
console.log('custom scroll failed', e);
}
location.origin+location.pathname+
location.search+location.hash.substring(1)
)
let urlQueryParam = currentUrlWithoutHash.searchParams
let isUrlHasIdQuery = urlQueryParam.has(TARGET_QUERY)
if(isUrlHasIdQuery){
let urlId = urlQueryParam.get(TARGET_QUERY)
// run delayed, to make sure everything loaded
setTimeout(function() {
try{
document.querySelector('#'+urlId)
.scrollIntoView()
} catch(e){ console.log('custom scroll failed',e) }
}, SCROLL_DELAY);
}

Expand Down

0 comments on commit 610f22a

Please sign in to comment.