Is there a way to toggle widget animations?

So when I press the shift key a stamina progress bar should fade in and when I release the key it should fade out. My question is if there is a way to toggle the animation so that it is reverse and fades out seamlessly, when you stop pressing the key

Thanks to everyone who responds