-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
let contactSection = document.getElementById('contact'); | ||
let contactButton = document.querySelector('a[href="#contact"]'); | ||
|
||
function getSectionPosition() { | ||
let rect = contactSection.getBoundingClientRect(); | ||
let scrollTop = window.scrollY || document.documentElement.scrollTop; | ||
return { | ||
top: rect.top + scrollTop, | ||
height: rect.height, | ||
bottom: rect.top + scrollTop + rect.height | ||
}; | ||
} // get position of #contact section | ||
|
||
function toggleButtonVisibility() { | ||
let sectionPos = getSectionPosition(); | ||
let scrollTop = window.scrollY || document.documentElement.scrollTop; | ||
let viewportHeight = window.innerHeight; | ||
let scrollBottom = scrollTop + viewportHeight; | ||
|
||
if (window.innerWidth >= 768) { | ||
let inView = (scrollBottom > sectionPos.top) && (scrollTop < sectionPos.bottom); | ||
if (inView) { | ||
contactButton.classList.add('md:hidden'); | ||
} else { | ||
contactButton.classList.remove('md:hidden'); | ||
} | ||
} else { | ||
contactButton.classList.add('md:hidden'); | ||
} | ||
} // update button visibility based on the scroll position | ||
|
||
toggleButtonVisibility(); | ||
window.addEventListener('scroll', toggleButtonVisibility); // listener to update button visibility | ||
window.addEventListener('resize', toggleButtonVisibility); // listener to recheck visibility if screen resized | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters