Is there a way to limit how far a fixed background image can scroll down a page? Essentially, is it possible to change the background attachment to static when the bottom of the background image is 10px away from the bottom edge of its div container?
In the code snippet below, how can I make the coral gradient (placeholder for an image) stop scrolling with the page once it reaches 10vh away from the border between the red and yellow divs? (Preferably using CSS only, but open to JavaScript solutions as well)
.red {
position: absolute;
top: 0;
height: 100vh;
width: 100vw;
background: red fixed linear-gradient(lightcoral, lightcoral) 45vw 20vh / 20vh 20vh no-repeat;
}
.yellow {
position: absolute;
top: 100vh;
height: 100vh;
width: 100%;
background-color: yellow;
}
<div class="red"></div>
<div class="yellow"></div>
Appreciate any assistance!