Я все еще относительно новичок в кодировании, но я следовал учебному пособию для набора ударных, а затем сделал свой собственный, который можно показать здесь: https://jonathanbeuzelin.github.io/mydrumset/index.html
Когда клавиша удерживается в течение длительного периода времени, переход зафиксируется и не вернется к своему нормальному состоянию.
<script type="text/javascript">
function playSound(e) {
const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`);
const key = document.querySelector(`.key[data-key="${e.keyCode}"]`);
if (!audio) return; // stop the function from running all together
audio.currentTime = 0; // this will rewind it to the start
audio.play();
console.log(key);
key.classList.add('playing');
}
function removeTransition(e){
if(e.propertyName !== 'transform') return; // skip it if its not a transform
this.classList.remove("playing")
}
const keys = document.querySelectorAll('.key');
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
window.addEventListener('keydown',playSound);
</script>