在调整容器 DIV 大小期间隐藏 iframe 会加快响应速度吗?

发布于 2024-12-06 08:11:25 字数 226 浏览 2 评论 0原文

各位,

我有一个包含许多 IFrame 的 DIV(长话短说)。用户可以调整 DIV 的大小,iFrame 的大小也会随之改变。然而,调整大小的过程缓慢且不稳定,大小会“突发”变化。

在调整大小期间隐藏 iFrame 会加快速度吗?

是否有暂时隐藏 iFrame 的最佳实践?我似乎记得其他地方的人推荐了一些有点奇特的方法来隐藏它们,尽管我不记得为什么。

谢谢, 安·L。

Folks,

I have a DIV that contains a number of IFrames (long story). The DIV can be resized by the user, and the iFrames change size along with it. However, the resizing process is slow and choppy, with the size changing in "bursts".

Would hiding the iFrames during the resize speed this up?

Is there a best practice for temporarily hiding an iFrame? I seem to remember people elsewhere recommending slightly exotic methods for hiding them, although I don't recall why.

Thanks,
Ann L.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情魔剑神 2024-12-13 08:11:25

另一种选择是显示要应用调整大小的区域的“边界框”或“预览”。类似于 在此处调整示例大小时看到的虚线边框

Another option would be to show a 'bounding box' or 'preview' of the area in which you are applying the resize. Similar to The dotted border you see when re sizing the example here

夜声 2024-12-13 08:11:25

解决此问题的一种方法是不在调整大小事件上执行实际的调整大小(这会导致不稳定,因为它经常被调用),而是在调整大小时设置一个计时器,并且仅在窗口发生时才执行实际的调整大小大小有一两秒没有改变。然后,用户可以自由调整窗口的大小,当他们暂停时,它会在没有任何中间不稳定的情况下布置内部。一般来说,它的工作原理如下:

var resizeTimer = null;

function doActualResize() {
    resizeTimer = null;
    // do your window interior resize here 
    // won't get called more than once per second because of timer
}

window.onresize = function() {
    // clear any prior timer that hasn't fired yet
    if (resizeTimer) {
        clearTimeout(resizeTimer);
    }
    // set new timer to wait for 1 second of no further resize motion
    resizeTimer = setTimeout(doActualResize, 1000);
}

One way to solve this problem is to not carry out the actual resize on the resize event (which leads to the choppiness because it gets called so often), but rather to set a timer on the resize and only do the actual resize when the window size hasn't changed for a second or two. Then, the user can freely resize the window and when they pause, it lays out the interior without any of the intermediate choppiness. In general, it works like this:

var resizeTimer = null;

function doActualResize() {
    resizeTimer = null;
    // do your window interior resize here 
    // won't get called more than once per second because of timer
}

window.onresize = function() {
    // clear any prior timer that hasn't fired yet
    if (resizeTimer) {
        clearTimeout(resizeTimer);
    }
    // set new timer to wait for 1 second of no further resize motion
    resizeTimer = setTimeout(doActualResize, 1000);
}
听你说爱我 2024-12-13 08:11:25

屏幕上的内容越少,回流速度越快。如果您可以隐藏元素,直到复杂的 DOM 更改完成,您将在最后强制进行额外的重绘,但中间步骤应该更快。

The less there is on the screen, the faster the reflow. If you can hide elements until a complex DOM change is complete you'll force an additional redraw at the end, but the intermediate steps should be faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文