Website: Update documentation scroll event handler (#12547)

Changes: 
- Updated the event handler for the sticky right-side navigation and the
"Back to the top" button on docs pages only to run if those elements
exist, and disabled the event handler on the documentation landing page.
This commit is contained in:
Eric 2023-06-27 17:56:03 -05:00 committed by GitHub
parent 4c073278a8
commit d050f7f1f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -77,7 +77,9 @@ parasails.registerPage('basic-documentation', {
return pagesBySectionSlug;
})();
// Adding a scroll event listener for scrolling sidebars and showing the back to top button.
window.addEventListener('scroll', this.handleScrollingInDocumentation);
if(!this.isDocsLandingPage){
window.addEventListener('scroll', this.handleScrollingInDocumentation);
}
},
mounted: async function() {
@ -269,7 +271,7 @@ parasails.registerPage('basic-documentation', {
let backToTopButton = document.querySelector('div[purpose="back-to-top-button"]');
let scrollTop = window.pageYOffset;
let windowHeight = window.innerHeight;
// If the right nav bar exists, add and remove a class based on the current scroll position.
if (rightNavBar) {
if (scrollTop > this.scrollDistance && scrollTop > windowHeight * 1.5) {
rightNavBar.classList.add('header-hidden', 'scrolled');
@ -279,12 +281,14 @@ parasails.registerPage('basic-documentation', {
rightNavBar.classList.remove('header-hidden');
}
}
if (backToTopButton && scrollTop > 2500) {
backToTopButton.classList.add('show');
} else if (scrollTop === 0) {
backToTopButton.classList.remove('show');
// If back to top button exists, add and remove a class based on the current scroll position.
if (backToTopButton){
if (scrollTop > 2500) {
backToTopButton.classList.add('show');
} else if (scrollTop === 0) {
backToTopButton.classList.remove('show');
}
}
this.scrollDistance = scrollTop;
},
clickScrollToTop: function() {