jquery如何检测文档大小变化
因此,假设单击某些内容会导致新内容加载到屏幕上,从而导致文档的高度发生变化,而以前没有滚动条,现在实际上有滚动条...
检测发生类似的情况
我如何使用 jquery绑定 窗口上的调整大小事件仅检测窗口调整大小,而将其绑定到文档中则不起作用
so suppose that clicking something would lead to a new content being loaded to the screen hence the height of document changes and whereas previously there are no scroll bars, now there actually are scrollbars...
how do I detect something like that happening using jquery
binding resize event onto window only detects window resize whereas binding it into document doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:
请不要使用
DOMSubtreeModified
事件。它很旧、已被弃用并且不受浏览器的良好支持。在 99.9% 的情况下,您可以收听不同的事件。您很可能是使用 jQuery 并执行一些 AJAX 操作的人之一,因此请查看他们的 AJAX 文档。这些都是可用的事件。您必须检测
$(document).bind('DOMSubtreeModified', function() { ... });
并检查上次触发的尺寸变化。每当对 DOM 执行任何操作时,都会触发此事件。因此,它会减慢您的浏览器速度。
我们应该有更好的选择。您能否向我们提供有关您的场景的更多信息?
Update:
Please don't use the
DOMSubtreeModified
event. It is old, deprecated and not well-supported by browsers. In 99,9 % of the cases, there is a different event you can listen on. Most likely you are one of those people using jQuery and doing some AJAX stuff, so please take a look at their AJAX docs.These are all available events. You would have to detect
$(document).bind('DOMSubtreeModified', function() { ... });
and check for a dimension change to the previous firing.This event is firing every time anything is done to the DOM. Therefore it will slowdown your browser.
We should get a better alternative. Could you please give us more information to your scenario?
这是解决方案。
Here is the solution.
您可以尝试像这样的百分比滚动事件:
http://www.jquery4u.com/snippets/jquery-detect-scrolled- page/
您可能需要添加一个检查来查看垂直滚动条是否存在:
You could try a percentage scrolled event like this one:
http://www.jquery4u.com/snippets/jquery-detect-scrolled-page/
You might need to add a check to see whether the vertical scrollbar is present: