Created
January 24, 2016 17:22
-
-
Save jacoyutorius/c77a2e422916cdf7f739 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Click Counter</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.6/react-dom.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> | |
| <style media="screen"> | |
| div.typewriter { | |
| font-size: 55px; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="content"> | |
| </div> | |
| <audio id="input_sound" src="./sound/meka_ka_type02.mp3"> | |
| <audio id="enter_sound" src="./sound/meka_ge_type_kaigyo01.mp3"> | |
| <script type="text/babel"> | |
| var TypeWriter = React.createClass({ | |
| getInitialState(){ | |
| return { | |
| input_text: "" | |
| } | |
| }, | |
| onChange(){ | |
| play_sound("input_sound"); | |
| this.setState({ | |
| input_text: $("#typewriter_input")[0].value | |
| }); | |
| }, | |
| onKeyDown(event) { | |
| // console.log(event.keyCode); | |
| if(event.keyCode == "13"){ | |
| play_sound("enter_sound"); | |
| } | |
| }, | |
| render() { | |
| return ( | |
| <div className="typewriter"> | |
| <input type="text" id="typewriter_input" onChange={this.onChange} onKeyDown={this.onKeyDown}></input> | |
| <div> | |
| <text>{this.state.input_text}</text> | |
| </div> | |
| </div> | |
| ); | |
| } | |
| }); | |
| function play_sound(name){ | |
| document.getElementById(name).currentTime = 0; | |
| document.getElementById(name).play(); | |
| } | |
| ReactDOM.render( | |
| <TypeWriter />, | |
| document.getElementById("content") | |
| ); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment