I am trying to create a tooltip above an input carriage in a text area. It would be easy if I could get the x, y coordinates of the carriage in the text area, however I was looking a bit and cannot figure out how to do this.
Say the user enters a text area and then presses a key (for example, the @ character). I am trying to show a little hint above the text area caret.
Any ideas?
Hmmm I really don't see anything in jQuery events that will easily provide you with the xy coordinate for the caret.
However, there are several ways to determine the caret position in a text field:
http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html
Is it possible to programmatically determine the position of the carriage in the <input type = text> element?
Caret position in the text box, in characters from the beginning
Using this, you can try to estimate the coordinates of the pixels for the tool tip.
If you want this to be more accurate, use a monospace font inside your text fields.
//depending on size of font var charWidth = 10; //using any number of the above methods to get caret position var caretPosition = getCaretPos('#myTextField'); var textFieldOffsetX = $('#myTextField').offset.left; var toopTipPositionX = caretPosition * charWidth + textFieldOffsetX;
It is not accurate and will not be perfect, but it can be close enough.
Why should the tooltip be in the carriage? Why not place it above (or somewhere nearby) in a text box? Here is a demo of what I mean.
$('textarea').keyup(function(e) { switch (e.which) { // @ symbol case 50: makeTooltip(e, 'you typed in an at symbol'); break; } });
Source: https://habr.com/ru/post/898318/More articles:OpenGraph Music music.listens returns an error - facebookOpengraph and music.listen - opengraphhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/898315/programmatically-access-to-tfs-2010-from-outside-the-domain&usg=ALkJrhjk__f4aMcm3LOVYNiovoIf59ZIywUsing common open objects and graph actions and publish_actions permission? - opengraphWebcal on Android - androidWindows EXE can work as a service or application. How can I determine if it works as a service or not? - cWhich asynchronous Ruby server should I use? - ruby | fooobar.comTopshelf debugging application debugging in VS2010 - c #A few questions about SQLite database courses in Android - androidLike button Do not show calculations - facebookAll Articles