I made a very primitive example using a bit of Js, to serve as a basis. I think it will solve your problem when you apply the styles. I opted to use pure js for you to have a greater understanding of what's going on, but you could use JQuery as well or bootstrap features! If you want to know more about the subject search about Affix, follow some links:
Affix with Bootstrap 3: link
W3Schools on affix: link
window.onscroll = scroll;
function scroll() {
var scrollTop = window.pageYOffset;
if (scrollTop > 30) {
try {
document.getElementById('antes').id = 'depois'
} catch (e) {
false
}
} else {
try {
document.getElementById('depois').id = 'antes'
} catch (e) {
false
}
}
}
body {
height: 1000px
}
main {
position: relative;
top: 60px
}
#antes {
height: 50px;
width: 100%;
z-index: 10;
position: fixed;
transition: all 0.5s ease-in-out;
background-color: blue;
}
#depois {
height: 50px;
width: 100%;
z-index: 10;
position: fixed;
transition: all 0.5s ease-in-out;
background-color: green;
opacity: 0.9;
}
<div id='antes'>
Hello world!
</div>
<main>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam a fermentum nisl. Sed id elementum est. Vivamus pharetra scelerisque mauris ut lobortis. Suspendisse gravida luctus orci volutpat tincidunt. Donec a erat luctus, rhoncus orci condimentum,
aliquet nunc. Nulla varius nisi a pretium pretium. Phasellus et mattis mi. Suspendisse efficitur elit eget libero laoreet ornare. Sed eget tristique erat. Vestibulum nec nulla in massa cursus feugiat. Mauris aliquam dolor in auctor fringilla. Maecenas
efficitur quam vel pellentesque faucibus.
</main>