I have implemented a jQuery and CSS code to reveal my contact form as I scroll down the page. However, I am facing an issue with setting a specific range for displaying the element while scrolling. Currently, I have only managed to handle the scrolling down and hiding functionality. I need assistance in developing the code to display this object within the range of 200px - 1024px.
If anyone has an idea on how to achieve this, please share your solution with me.
Please refer to this animated gif: OR https://ibb.co/6y7wCmK
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;
if (1600 > currentScrollPos) {
document.getElementById("sticky").style.top = "200px";
} else {
document.getElementById("sticky").style.top = "-1000px";
}
prevScrollpos = currentScrollPos;
}
/* Test contact-sticky*/
.sticky {
position: fixed;
transition: top 0.3s;
top: -1000px;
left: 827px;
right: 46px;
background-color: #ebc11d;
padding: 50px;
font-size: 14px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
<p class="sticky">Contact form</p>