Hey everyone! I'm currently grappling with a project that requires me to keep a div stuck to the screen (prevent scrolling) when its bottom reaches the bottom of the screen. I have two divs on the page, both with varying heights. My aim is to keep div2 stuck while allowing div1 to scroll.
<script>
var divheight
var scrolltop
var screenheight
if(divheight-scrolltop <= screenheight){
/* I need to find a way to keep the div in place without using fixed positioning, as both divs are floating. */ }
else { /* Release the div */ }
</script>
I'm stuck on what to include in the if and else conditions. Any help would be greatly appreciated!