I have a radio button inside of a div:
<div>
<input type='radio' class='radio-btn'>
</div>
The background of the div is a linear gradient:
background-image: linear-gradient(to bottom, #ffffff, #fdfdfd, #fbfcfb, #fafafa, #f8f8f8, #f5f5f5, #f1f1f1, #eeeeee, #e8e8e8, #e1e1e1, #dbdbdb, #d5d5d5);
When I click on the input button, I want to change the background of the containing div to GREEN without a transition, then immediately have the green fade out and go back to the original linear gradient.
So far this is what I have:
let radioBtn = document.querySelector('.radio-btn');
radioBtn.addEventListener('click', function(e){
function changeColor(){
e.target.parentElement.style.transition = '0s';
e.target.parentElement.style.background = 'green';
}
function fadeColor(){
e.target.parentElement.style.transition = '0.3s';
e.target.parentElement.style.background = 'linear-gradient(to bottom, #ffffff, #fdfdfd, #fbfcfb, #fafafa, #f8f8f8, #f5f5f5, #f1f1f1, #eeeeee, #e8e8e8, #e1e1e1, #dbdbdb, #d5d5d5)';
}
changeColor();
setTimeout(fadeColor, 100);
})
This changes the color to green, waits 100ms, then changes it back to the original linear gradient but without the transition. I've tinkered with the code but cannot get it to fade out...is there another way to do this?
Thanks!