-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaccessibility-improvements.js
More file actions
27 lines (24 loc) · 936 Bytes
/
accessibility-improvements.js
File metadata and controls
27 lines (24 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
document.addEventListener('DOMContentLoaded', () => {
const backToTopButton = document.getElementById('backToTop');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
backToTopButton.classList.remove('hidden');
backToTopButton.classList.add('visible');
// Optionally, set focus to the button when it becomes visible
// backToTopButton.focus();
} else {
backToTopButton.classList.remove('visible');
backToTopButton.classList.add('hidden');
}
});
}, {
rootMargin: '0px',
threshold: 0.1 // Adjust threshold based on requirement
});
// Observe a specific target, in this case, a footer or a bottom marker element
const pageBottom = document.querySelector('#page-bottom');
observer.observe(pageBottom);
});
function scrollToTop() {
window.scrollTo({top: 0, behavior: 'smooth'});