admin管理员组文章数量:1333626
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: /
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/lborgman/L8k5ggnk/3/
Share Improve this question edited Dec 30, 2014 at 22:40 Leo asked Dec 30, 2014 at 21:48 LeoLeo 4,4387 gold badges54 silver badges83 bronze badges 6- I am curious what you want to use it for. – jbg Commented Dec 30, 2014 at 21:50
-
@jbg, Just a rewrite of plete.ly.js. It uses a "background"
<input>
-tag to display a hint. I want to scroll the text in the hint when the text in the main<input>
is scrolled. – Leo Commented Dec 30, 2014 at 21:53 -
1
An
input
does fire ascroll
event when the overflowing text "scrolls" via change in overflow, at least in Firefox. – Alexander O'Mara Commented Dec 30, 2014 at 21:57 -
1
@Leo I'm not sure, but a
scroll
event doesn't fire in Chrome unfortunately, despite the fact that it has thescrollLeft
property. – Alexander O'Mara Commented Dec 30, 2014 at 22:06 - 1 Here is a reported bug at bugs.chromium/p/chromium/issues/detail?id=1007153, thanks – 4esn0k Commented Sep 24, 2019 at 6:06
2 Answers
Reset to default 6There 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 plete, but if I have missed any, let me know!
Have you tried the Caret Plugin?
You can get the position of the caret with:
pos = $(textarea).caret()
and catch when it changes again. If the latter is different than the first then you know the user has moved inside the input.
本文标签: javascriptEvent to detect when the text in an ltinputgt is scrolledStack Overflow
版权声明:本文标题:javascript - Event to detect when the text in an <input> is scrolled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351834a2458650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论