Does anyone know how to change the character of a textfield caret with javascript?
Like the title reads, I want to change the character of开发者_StackOverflow社区 a caret. Maybe make it a letter or something?
Thanks.
You can do something near this, but its very dificult.
- In you textfield bind a event to keydown, for example.
- Each char typed, you slide a floating
<img>
above textarea. - If user click in textarea, update position getting X and Y from onclick.
Obs: the font must be monospaced. Ex: if every font have 20px and user press backspace, you slide this gif to the left 20px.
EDIT
I just made a hello world, in jsfiddle.
Of course, it's an example, but test typing and use backspace and enter to see caret go back and foward.
In this example there are a lot of bugs to fix, like:
Use of
<backspace>
that cleans all lineUse of arrows that in overflow textarea margins
Use of mouse must update caret position...
That's not possible in HTML/JavaScript.
精彩评论