I have a bunch of multiline content ads arranged vertically, and I want to allow natural navigation between them using the arrow keys (as if it were a single document). For this, in the keydown event keydown I need:
- Know the current line for the caret and the number of lines to determine whether we need to move up (the first line and the button is pressed) or down (the last line and & darr;)
- Know the current character (position in the line shown) to determine whether we need to move up (position == 0 and & larr; key pressed) or down (position == text.length and & rarr, pressed)
- The process should not stop between switching elements when the key is held and not released (therefore, a
keydown event, not a keyup ) - Preferred: the event should stop propagating (for example, if I am in the first column in the last row and I press & darr; key, it should not go to the last character on the line and then go down)
- Preferred (it would be really awesome): after we move on to the next element, we would not just a
.focus() element, but emulate the click in the same vertical position as before, so that it feels natural as in text editors.
All scripts / libraries that I have found to date either do not do everything that I need or do not work. Please include demos in your suggestions so that I can test without first including my code. Thanks!
Update: Visual explanation - note that there are more than two sections, and the down arrow on the last line is only one of four triggers

source share