Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event to detect when the text in an <input> is scrolled?

Is there an event that is fired when the text inside an <input>-tag is scrolled? I mean when the text inside is to long and you move the input caret to the end of it, etc.

There is a scroll event you can catch on the element when that is scrolled in the layout, but that is not what I want.

UPDATE: Here is a fiddle to test the events discussed: http://jsfiddle.net/lborgman/L8k5ggnk/3/

like image 418
Leo Avatar asked Dec 30 '14 21:12

Leo


1 Answers

There is no specific event for this that will work across browsers. Firefox does fire a scroll event when the text "scrolls" by changing the insertion point, but Chrome and likely other browsers don't.

Here is a list of events that could change the insertion point.

  • input
  • keydown
  • keyup
  • focus
  • blur
  • click
  • change
  • paste
  • cut
  • scroll
  • wheel
  • dragover

Binding an event listener to all of these should be enough to respond to the insertion point changing. I believe the list above is complete, but if I have missed any, let me know!

like image 189
Alexander O'Mara Avatar answered Sep 21 '22 05:09

Alexander O'Mara