如何检测jquery的文档尺寸变化 [英] how to detect document size change in jquery
问题描述
这样假设一下东西会导致新的内容加载到屏幕上,因此文件的变化和而$ P $高度pviously没有滚动条,现在其实有滚动条...
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...
我怎么发现这样的事情发生使用jQuery
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
推荐答案
更新:结果
请不要使用 DOMSubtreeModified
事件。这是旧的,德precated并通过浏览器不能很好的支持。在的情况下,99.9%,还有你可以听在不同的事件。最有可能你是使用jQuery,做一些AJAX的东西的那些人之一,请看看他们的 AJAX文档。
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.
这些都可用事件。你将不得不检测的$(document).bind('DOMSubtreeModified',函数(){...});
并检查是否有尺寸变化到previous射击。
These are all available events. You would have to detect $(document).bind('DOMSubtreeModified', function() { ... });
and check for a dimension change to the previous firing.
var height = $(this).height(),
width = $(this).width();
$(document).bind('DOMSubtreeModified', function() {
if($(this).height() != height || $(this).width() != width) {
recalibrate();
}
});
此事件被触发的每个时间什么做是为了DOM。因此,它的会放缓您的浏览器。
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?
这篇关于如何检测jquery的文档尺寸变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!