Get carriage position in x and y coordinates in javascript

I am trying to find the current carriage position (flashing |) in the x and y coordinates. Does anyone have a way to do this? I really don't know where to start.

I know that this is possible in javascript, because there is a jQuery plugin for it, but I want to do it without jQuery.

In particular, I'm interested in how Google Instant displays selection # 1 as gray text. I plan to do this for both text fields and text fields by getting the caret position (as I mentioned above) and then placing the text using absolute positioning. If anyone has a better way to do this, let me know.

Thanks!

+4
source share
2 answers

I would say that you better put the entire guessed line (including the text typed so far) as the background of the background label and make the input field transparent.

Positioning the input field and div should be trivial. This way you can make the shortcut gray and it will give the same effect.

Will this work?

EDIT: Checked by what Google is doing. They have two input fields located one above the other, and the assumption is filled with the input background

+1
source

You need to follow the mouse movement events and get the coordinates from the movement.

-1
source

Source: https://habr.com/ru/post/1337546/


All Articles