function fixHeight() {
var headerHeight = $("#switcher").height();
$("#iframe").attr("height", $(window).height() + "px");
}
$(window).resize(function() {
fixHeight();
}).resize();
//iframe页面自适应
function setIframeHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight - 20;
}
}
}
js自适应
最新推荐文章于 2024-11-18 22:18:13 发布
本文介绍了一种通过JavaScript实现IFrame自适应高度的方法。利用$(window).resize()监听窗口大小变化并调整IFrame的高度,确保IFrame内容能完全显示且不出现滚动条。适用于网页布局需要IFrame元素随着浏览器窗口大小变化而自动调整的情况。
902

被折叠的 条评论
为什么被折叠?



