File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 6060< script >
6161 window . addEventListener ( 'keydown' , function ( e ) {
6262 const audio = document . querySelector ( `audio[data-key="${ e . keyCode } "]` ) ;
63- console . log ( audio )
63+ const key = document . querySelector ( `.key[data-key=" ${ e . keyCode } "]` ) ;
6464 if ( ! audio ) return ; //stop function all together
6565 // note if call .play on audio element already playing, it won't play again. so if press "F" in successsion it will only play every 5 sec
6666 audio . currentTime = 0 ; //rewind to the start, so that it can be played many times quickly
6767 audio . play ( ) ;
68-
68+ // CSS: transition:all .07s;
69+ //.playing adds transform:scale(1.1);
70+ key . classList . add ( 'playing' ) ;
6971 } ) ;
72+
73+ function removeTransition ( e ) {
74+ if ( e . propertyName !== 'transform' ) return ; // skip it if its not a transform
75+ // here this = key div
76+ this . classList . remove ( 'playing' ) ;
77+ }
78+
79+ const keys = document . querySelectorAll ( '.key' ) ;
80+ keys . forEach ( key => key . addEventListener ( 'transitionend' , removeTransition ) ) ;
7081</ script >
7182
7283
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ body,html {
2323 margin : 1rem ;
2424 font-size : 1.5rem ;
2525 padding : 1rem .5rem ;
26- transition : all .07 s ;
26+ transition : all .1 s ;
2727 width : 100px ;
2828 text-align : center;
2929 color : white;
You can’t perform that action at this time.
0 commit comments