javascript - 在 Chrome 和 Edge 中使用 Javascript 更改 iFrame 大小闪烁
问题描述
我正在使用本机库动态更改 iframe 大小ResizeObserver
,PostMessage
但每次 iframe在Chrome和Edgewidth
中更改大小(和height
)时,它都会闪烁。这真的很奇怪,因为在Firefox和Safari中它按预期工作。
这是我的代码
// Child window
const resize = new ResizeObserver(entries => {
window.parent.postMessage({ updateIframeSize: { width, height } }, *);
});
resize.observe(document.body);
// Main window
window.addEventListener('message', function (message) {
const iframeSizeEvt = message.data.updateIframeSize;
if (iframeSizeEvt) {
const iframeTag = document.getElementById('myIframe');
iframeTag.style.width = `${iframeSizeEvt.width}px`;
iframeTag.style.height = `${iframeSizeEvt.height}px`;
}
});
// Iframe
<iframe id="myIframe" src="MY_IFRAME_URL" style="position: fixed; right: 0; bottom: 0; width: 100px; max-width: 100%; height: 100px; max-height: 100%; border: 0; background-color: transparent; opacity: 1; overflow: hidden; z-index: 1000000; box-sizing: border-box;"></iframe>
我还测试了transform: translate3d(0, 0, 0)
在 iframe 上添加但没有成功。
有人知道如何解决这种奇怪的眨眼行为吗?
解决方案
推荐阅读
- python - 列表理解中的生成器表达式未按预期工作
- android - 如何像垂直 Viewpager 变换一样为 RecyclerView 设置动画
- java - 从 postgres 数据库中获取二进制图像数据并保存在文件夹中
- jpa - 与他人共享 OneToMany 的最佳做法是什么?
- c# - PDF4Net:段落最后一行的文本对齐
- node.js - 根据节点请求使用异步函数中可用的数据来更新应用程序的数据
- ios - 缺少 Info.plist 值 - Info.plist 键“CFBundleIconName”的值
- angular - 自定义复选框背景图像未出现-Angular 5部署后的Bootstrap 4
- python - Python 问题:TypeError: unhashable type: 'slice' during web scraping
- android - 进度对话框永远不会出现