So I'm trying to animate a css property based on scrolling the browser window. the code below works so far, but I'd like it to have a transition instead of just abruptly snapping from an opacity of 1 to an opacity of 0.5. any help is appreciated. thanks in advance.
$(document).ready(function(){
$(window).scroll(function(){
if ($(window).scrollTop() > 50){
$('.header').css('background','rgba(200, 54, 54, 0.5)');
}
else if ($(window).scrollTop() < 50){
$('.header').css('background','rgba(200, 54, 54, 1)');
}
});
});
Here is a jsfiddle link to the code so far