開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- JavaScript (プログラミング言語)
- Safari(Web browser)
Head First JavaScript Programming (Eric T. Freeman (著)、Elisabeth Robson (著)、O'Reilly Media)の Chapter 9.(Handling events - Asynchronous Coding)の EXERCISE(No. 6015)を取り組んでみる。
EXERCISE(No. 6015)
コード(Emacs)
HTML5
<pre id="output0"></pre> <button id="run0">run</button> <button id="clear0">clear</button> <br> <img id="map" width="600" height="200" src=""> <p id="coords">Move mouse to find coordinates…</p> <script src="sample2.js"></script>
JavaScript
let btn0 = document.querySelector('#run0'), btn1 = document.querySelector('#clear0'), pre0 = document.querySelector('#output0'), p = (x) => pre0.textContent += x + '\n'; let b0 = document.querySelector('body'); let init = () => { let map = document.querySelector('#map'); map.onmousemove = showCoords; }; let showCoords = (event) => { let coords = document.querySelector('#coords'); let x = event.pageX, y = event.pageY; coords.textContent = `Map coordinates: ${x}, ${y}`; }; let output = () => { init(); }; let clear = () => {}; btn0.onclick = output; btn1.onclick = clear; output();
Move mouse to find coordinates…
0 コメント:
コメントを投稿