javascript 主体调整大小时的 Jquery 触发器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13844414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery trigger on body resize
提问by Joel
I have a page that has content that is modified by javascript. I want to create some kind of event listener that triggers when the content's size changes. I do not want this:
我有一个页面,其中包含由 javascript 修改的内容。我想创建某种在内容大小更改时触发的事件侦听器。我不想要这个:
$(window).resize(...);
This triggers when the window size changes - for example when the user re-sizes the browser window. I tried this:
这会在窗口大小发生变化时触发 - 例如,当用户重新调整浏览器窗口的大小时。我试过这个:
$('body').resize(...);
However it does not trigger. How can I create an event that triggers when the content causes the page size to change? I am also open to plain javascript solutions.
但是它不会触发。如何创建在内容导致页面大小更改时触发的事件?我也对普通的 javascript 解决方案持开放态度。
回答by gotohales
By default jQuery will only let you use that event on window
but there is at least one pluginout there that will let you bind it to other elements. I would recommend using that.
默认情况下,jQuery 只允许您使用该事件,window
但至少有一个插件可以让您将其绑定到其他元素。我会建议使用它。
With this you could then do something similar, like
有了这个,你就可以做类似的事情,比如
$("#unicorns").resize(function(e){
// do something when #unicorns element resizes
});
回答by ToNiK
U can use such approach:
你可以使用这样的方法:
$(elem).append('<iframe id="frame0" name="frame0" width=100% height=100% style="position:absolute;top:0px;z-index:-1"></iframe>');
frame0.onresize = function() {
//..do something ””
}
And this will trigger on each elem size change;)
这将在每个元素大小变化时触发;)