I want a semi transparent div to 'disappear' behind a second semi transparent div when the user scrolls up. I'm trying to avoid any overlapping opacity. Both divs share the same background image, which I also want to scroll with the page.
EDIT:
This works. To solve the overlapping opacity I duplicated the body background on the top div and gave it a higher z-index. When the user scrolls up the content disappears behind this layer.
To solve the problem of the background not scrolling I based it on this solution to scrolling a background image > jQuery on window scroll animate background image position
I changed the values so the top div and body background move simultaneously so it appears that the single background image is moving.
jsfiddle >>> https://jsfiddle.net/1rw4khgm/1/
$('document').ready(function(){
$('#bottom').scroll(function(){
var x = $(this).scrollTop();
$('#top').css('background-position','0% '+parseInt(-x)+'px');
$('body').css('background-position','0% '+parseInt(-x)+'px');
});
});
body {
margin: 0;
background-image: url("https://i.ibb.co/PDrJKf7/chrissa-giannakoudi-0-QRZk-Whfc-A4-unsplash.jpg");
background-size: 100% auto;
background-position: 0% 0;
}
#top {
top: 0;
position: fixed;
height: 100px;
width: 100%;
background-image: linear-gradient(rgba(153, 50, 204, 0.7), rgba(153, 50, 204, 0.75)), url("https://i.ibb.co/PDrJKf7/chrissa-giannakoudi-0-QRZk-Whfc-A4-unsplash.jpg");
background-size: 100% auto;
background-position: 0% 0;
z-index:1;
}
#bottom {
position: relative;
top: 100px;
height: 300px;
width: 100%;
background-color: rgba(176, 224, 230, 0.7);
overflow : auto;
overflow-x : hidden;
overflow-y : auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<div id="top">
Nav
</div>
<div id="bottom">
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content5</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
<p>Content10</p>
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
</body>