File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change 5858 < audio data-key ="76 " src ="sounds/tink.wav "> </ audio >
5959
6060< script >
61- window . addEventListener ( 'keydown' , function ( e ) {
61+ function playSound ( e ) {
6262 const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
63+ const key = document . querySelector ( `.key[data-key="${ e . keyCode } "]` ) ;
6364 if ( ! audio ) return ; // this will stop the function from running all together
64-
65+ audio . currentTime = 0 ; // rebobina al principio y me permite reproducir cada vez que pulso la tecla
6566 audio . play ( ) ;
66- } ) ;
67+
68+ key . classList . add ( 'playing' ) ;
69+ }
70+
71+ window . addEventListener ( 'keydown' , playSound ) ;
72+
73+ function removeTransition ( e ) {
74+ if ( e . propertyName !== 'transform' ) return ; // lo debe saltar si la propiedad no es transform
75+ this . classList . remove ( 'playing' ) ;
76+ }
77+
78+ const keys = document . querySelectorAll ( '.key' ) ;
79+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
6780</ script >
6881
6982
You can’t perform that action at this time.
0 commit comments