I have a block that appears after scrolling 200px on the page
const navShareLink = document.getElementById('navShareLink');
document.addEventListener('scroll', function(e) {
if(window.scrollY > 200 && window.innerWidth > 576) {
navShareLink.style.display = "block";
} else {
navShareLink.style.display = "none";
}
});
.article-wrapper {
min-height: 200vh;
}
.article-wrapper p:first-of-type {
margin-top: 0;
}
footer {
min-height: 100vh;
background-color: #eee;
}
.sidemenu-shares {
z-index: 999;
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
justify-content: center;
position: fixed;
top: 0;
right: 0;
flex-wrap: nowrap;
gap: 40px;
}
.rectangle {
z-index: 998;
transition: opacity 0.5s;
padding: 5px;
height: 106px;
width: 23px;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 24px;
}
<div class="article-wrapper">
<div class="sidemenu-shares">
<div id="navShareLink" class="rectangle">
</div>
</div>
<div class="main-banner">
<h1>Title</h1>
</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
<div>Main content...</div>
</div>
<footer>
Footer...
</footer>
But when it reaches the end of the page where the footer is, I need it to hide back so that it does not climb into the footer
It's easy to do if the page has the same height, but for me it can be either 2500px or 5000px
Is it possible to somehow count the pixels in reverse order, but not from the beginning of the page, but let's say 300px from the end?
I tried to get the height of the whole page and subtract 300
I used document.documentElement.scrollHeight I thought I would just get a digital value like 4500, but in the end I get the output of this value in a pop-up window when I open the page
Alternatively, i can somehow hide this block when it touches the footer, is it possible to do it somehow?