I have a simple function that registers when a key is pressed, then applies a CSS flash animation to an element.
As seen in the below snippet, if you click into the snippet window and press the P key or the command key (OSX - only works in safari I believe), then a flash animation will be added the the nav element.
window.onkeydown = function(e) {
if (e.which == 91 || e.which == 80) {
document.getElementById("nav").classList.add('flash');
window.setTimeout(function() {
document.getElementById("nav").classList.remove('flash');
}, 100)
}
}
.flash {
animation: flash 0.5s 2 alternate ease-out;
}
@keyframes flash {
to {
background-color: orange;
}
}
<nav id="nav">
blahblahblah
</nav>
If i change it so that the if statement is if (e.which == 91 && e.which == 80) it no longer fires the animation.
I am trying to make it so that when the command+P buttons are pressed together, the flash animation fires