I want to change opacity in rgba color from 0.1 to 1.
I writen this code which you can see bellow, but I want to ask you if it can be written easier. And I found 1 problem in this code which I don't know solve. If I very fast scroll down, sometime happend opacity of color is only 0.695 and not 1.
And if I want to change only opacity of background color from id scrollDiv. How can I do it? For example if I will have in css for scrollDiv background color rgba(172,16,15,0) and I want to change only 0 from css.
$(document).ready(function() {
$(window).scroll(function() {
var opacity = "0.0" + $(window).scrollTop();
if ($(window).scrollTop() >= 100) {
opacity = "0." + $(window).scrollTop();
}
if ($(window).scrollTop() > 0 && $(window).scrollTop() < 333) {
$('#scrollDiv').css({"background-color": "rgba(0,0,0,"+ opacity*3 + ")"});
} if ($(window).scrollTop() === 0) {
$('#scrollDiv').css({"background-color": "rgba(0,0,0,0)"});
}
});
});