JavaScript
1// getElementByID
2// ↓
3 getElementById
関数やイベント名はリファレンスを見るようにしましょう。
【イベントリファレンス - Web 技術のリファレンス | MDN】
https://developer.mozilla.org/ja/docs/Web/Reference/Events
【document.getElementById - Web API インターフェイス | MDN】
https://developer.mozilla.org/ja/docs/Web/API/Document/getElementById
HTML
1<img id="it" src="https://placehold.jp/24/cc9999/993333/350x150.png">
CSS
1#it {
2 position: absolute;
3}
JavaScript
1var fex = 0;
2var fey = 0;
3document.onmousemove = function(e) { // ※
4 var fe = document.getElementById( 'it' ).style;
5 fex = e.clientX;
6 fey = e.clientY;
7 fe.left = fex + 'px'; // ※
8 fe.top = fey + 'px'; // ※
9}
10```**動くサンプル:**[https://jsfiddle.net/cg8nabvk/](https://jsfiddle.net/cg8nabvk/)
11
12
13---
14
15**追記:**
16
17おまけ。
18
19【jQuery(JavaScript)でマウス座標やウィンドウサイズを取得して確認するツール | EasyRamble】
20[http://easyramble.com/js-check-positions-and-sizes.html](http://easyramble.com/js-check-positions-and-sizes.html)
21
22【座標取得するプロパティのそれぞれの違い - 三等兵】
23[http://d.hatena.ne.jp/sandai/20091105/p1](http://d.hatena.ne.jp/sandai/20091105/p1)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/19 00:13