如何使文本区域内容以与输入相同的方式在溢出时水平滚动? (没有 "jumps")

How to make textarea content scroll horizontally on overflow in the same fashion as input? (without "jumps")

我想使用 one-line textarea(与 rows=1overflow-x:hidden;),但现在我有一个问题:与 input type="text" 不同,当它水平溢出时,当我们继续在其中输入内容时,内容会以 "jumps" 滚动:

这不利于打字工作流程(另请参阅 fiddle)。有没有一些简单的方法来解决这个问题(最好只使用 CSS),或者唯一的方法是设置一个 on('input',..) 处理程序,通过一些讨厌的像素计算检查我们是否到达了其中的行尾然后设置 textarea?

的水平滚动位置

这可以通过使用 white-space css 属性轻松实现:

white-space: nowrap;
overflow-x: hidden; /* don't add this if you want a scrollbar to appear */