Whenever the enter key is pressed, I want to make a red color appear briefly and then fade out quickly to create a blinking effect.
I attempted adding a new class on Keypress that would transition the opacity to 0:
function enterpressalert(e, text) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
document.getElementById('body').className = "show";
}
}
#body {
background-color: rgb(175, 30, 30);
opacity: .25;
transition: opacity 0.4s ease-in;
-ms-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-webkit-transition: opacity 0.4s ease-in;
}
#body.show {
opacity: 0;
transition: opacity 0.4s ease-out;
-ms-transition: opacity 0.4s ease-out;
-moz-transition: opacity 0.4s ease-out;
-webkit-transition: opacity 0.4s ease-out;
}
<body id="body" onKeyPress="enterpressalert(event, this)></body>