gpt4 book ai didi

javascript - 如何在不刷新页面的情况下调整 iframe 的大小?

转载 作者:行者123 更新时间:2023-12-03 09:46:49 29 4
gpt4 key购买 nike

我在 iframe 中嵌入了一些 swf,但只有当页面刷新时,iframe 才会调整大小,然后如果我选择其他一个,那么不仅会显示动画,还会显示背景的所有 swf。这就是我正在使用的

if ( 'resizeIframe' === $('#onPlayAction').val() ) {
var ifrEl = $('div.player-container iframe.page-iframe')[0];

$(ifrEl).show();
ifrEl.src = htmlPageBrowserUri;
ifrEl.onload = function() {
ifrEl.width = ifrEl.contentWindow.document.body.scrollWidth;
ifrEl.height = ifrEl.contentWindow.document.body.scrollHeight;
}
}

最佳答案

有三种方法可以做到这一点。

  1. 您可以在每次调整窗口大小时更改大小
$(window).on('resize', function (){

ifrEl.width = ... ;
ifrEl.height = ... ;

})
  • 您可以使用一些 jQuery 插件,例如 iFrame Resizer

  • 您可以使用一些漂亮的 CSS 技巧。去搜索responsive iframes using css,你会找到很多好的答案。

  • 希望这一切对您有所帮助。

    关于javascript - 如何在不刷新页面的情况下调整 iframe 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30998205/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com