Created
December 21, 2014 12:40
-
-
Save hkondo/bc0d9ce0f94c32075099 to your computer and use it in GitHub Desktop.
Synchronized TextArea
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
| <script> | |
| function sync() { | |
| var m = document.getElementById("main"); | |
| var s = document.getElementById("sub"); | |
| s.value = m.value; | |
| window.setTimeout( function() { | |
| s.focus(); | |
| s.selectionStart = m.selectionStart; | |
| s.selectionEnd = m.selectionEnd; | |
| s.scrollTop = m.scrollTop; | |
| m.focus(); | |
| }, 0); | |
| } | |
| </script> | |
| <textarea id="main" cols="" rows="" | |
| onInput="sync();" | |
| onKeyDown="sync();" | |
| ></textarea> | |
| <textarea id="sub" cols="" rows=""></textarea> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
selectionStart とかでなく,桁/行で位置を拾えるようになると,またちょっと面白いことができそう.
安直には,改行コードで分割して数を数えればいいのかな?
http://oshiete.goo.ne.jp/qa/6845292.html
ブラウザ内での座標とかも計算できるから,これはこれで面白いことができそう.
http://d.akiroom.com/2012-06/jquery-textarea-caret-position-javascript-library/