Javascript 检测文本区域中的滚动条
我想知道是否有人知道我将如何检测滚动条何时出现在 textarea
内。
我目前在 JavaScript 中使用 mootools,但在让它检测滚动条时遇到问题。
I was wondering if anybody knows how I would go about detecting when the scrollbar appears inside a textarea
.
I am currently using mootools for my JavaScript and I am having issues getting it to detect a scrollbar.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅此 jsFiddle http://jsfiddle.net/qKNXH/
See this jsFiddle http://jsfiddle.net/qKNXH/
我制作了 Tommaso Taruffis 代码的 jQuery“兼容”版本
它可以处理多个元素并接受:选择器、jQuery 对象或DOM 元素。
可以这样调用:
I made a jQuery "compatible" version of Tommaso Taruffis code
It can handle multiple elements and accepts: selectors, jQuery objects, or DOM elements.
It can be called like this:
即使在文本区域中,托马索的解决方案也能完美运行。但是,如果用户要在文本区域中键入内容,并且突然文本区域给自己一个滚动条,您的 JavaScript 将不会知道或被触发。因此您可能需要添加类似的内容
Tommaso's solution works perfectly, even with a text area. But if the user were to type in the textarea and suddenly the textarea gave itself a scrollbar, your javascript wouldn't know or be triggered.So you might want to add something like
对于 React,我发现 https://github.com/andreypopp/react-textarea-autosize< /a>
For React I've found https://github.com/andreypopp/react-textarea-autosize