且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jQuery调整大小在FireFox,Chrome和Safari上不起作用

更新时间:2023-12-04 23:12:46

我相信JavaScript调整大小事件仅适用于框架或窗口,不适用于DIV.

I believe the JavaScript resize event only applies to frames or windows, not to DIVs.

例如参见此页面:

onResize偶数处理程序用于在用户或脚本调整窗口或框架的大小时执行指定的代码.这使您可以查询窗口元素的大小和位置,动态重置SRC属性等.

The onResize even handler is use to execute specified code whenever a user or script resizes a window or frame. This allows you to query the size and position of window elements, dynamically reset SRC properties etc.

因此,如果要检测何时调整窗口大小,则在jQuery中应该使用$(window).resize(function() { });

So if you want to detect when the window is resized, in jQuery you should probably use $(window).resize(function() { });

如果您要观看DIV的大小,则取决于您的意图.如果您要使用JavaScript调整大小,则可以实现一种方法来执行调整大小并让其处理任何其他调整大小代码.

if you want to watch the size of a DIV, it depends on what your intention is. If you're resizing with JavaScript then you could implement a method to perform the resize and have that handle calling any other resize code.

否则,如果您只是在有人调整窗口大小时看着DIV调整大小,那么将调整大小的侦听器附加到窗口上,然后检查DIV是否已调整大小(即存储旧的)就不行了吗?的宽度/高度值,并在调整大小时检查它们)?

Otherwise, if you're just watching for the DIV to resize when someone resizes the window, wouldn't it just work to attach the resize listener to the window and then check if the DIV had been resized (i.e. store the old values of width / height and check them on resize)?

最后,您可以考虑在宽度上使用手表 /height属性,尽管我不知道这是否与浏览器完全兼容(认为这可能仅适用于Mozilla).我确实找到了此jQuery插件,看起来它可能会做同样的事情但是(稍作修改).

Finally, you could consider using watch on the width / height properties, although I don't know whether this is fully browser-compatible (think this might be Mozilla-only). I did find this jQuery plugin which looks like it might do the same thing though (with some slight modification).