jQuery 中的滚动条出现/消失事件?
jQuery 中有没有一种简单的方法来检测滚动条何时在具有 Overflow:auto 的 div 上出现和消失? (就像一个事件?手指交叉...)
(我不想查看 div 内容的高度)
Is there a simple way in jQuery to detect when scrollbars appear and disappear on a div that has overflow:auto? (Like an event? Fingers crossed...)
(I'd prefer not to have to look at the height of the content of the div)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实现此目的的另一种方法是使用scrollLeft或scrollTop检查是否存在滚动条:
Another way to achieve this is to check whether there are scrollbars present using scrollLeft or scrollTop:
正如其他人所说,没有简单的方法。这是我过去用来检测滚动条是否存在的一些代码。
在从 div 添加或删除内容后,您需要手动调用它,并且它可能仅在您在可见元素上调用它时才起作用,但这比从头开始要好。
As others have said, there is no easy way. Here's some code I've used in the past to detect if a scrollbar is present.
You'll manually need to call this after adding or removing content from the div and it probably will only work if you call it on visible elements, but it's better than starting from scratch.
据我所知,没有相关事件。
但是,您“可以”为此编写自己的特殊事件,我想您必须检查一下
对于高度和宽度。
如果
.innerHeight
超过.outerHeight
,应该可以检测到滚动条一个元素的值。
As far as I know, there is not event for that.
However, you "could" write your own special event for that, I guess you have to check
for the height and width.
It should be possible to detect scrollbars if the
.innerHeight
exceds the.outerHeight
value of an element.