Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iframe的高度百分比数学javascript_Javascript_Html_Iframe - Fatal编程技术网

iframe的高度百分比数学javascript

iframe的高度百分比数学javascript,javascript,html,iframe,Javascript,Html,Iframe,事情是这样的。。。我有一个外部加载的iframe,名为RadioFrame,我有一个本地iframe和我的页面内容。正如您会注意到的,我在框架中的src是空的,这是因为源代码在最后是通过javascript代码加载的。所有的工作都很完美,但我遇到的最大问题是,当我打开iframe上的display时,我会向下推我的内容,将其隐藏在溢出位置:隐藏在body中,以防止双行滚动条。我一直在尝试计算,框架的高度固定在34px,但内容高度与显示器大小和页面内容有关。我尝试用jQuery计算框架的高度,然后

事情是这样的。。。我有一个外部加载的iframe,名为RadioFrame,我有一个本地iframe和我的页面内容。正如您会注意到的,我在框架中的src是空的,这是因为源代码在最后是通过javascript代码加载的。所有的工作都很完美,但我遇到的最大问题是,当我打开iframe上的display时,我会向下推我的内容,将其隐藏在溢出位置:隐藏在body中,以防止双行滚动条。我一直在尝试计算,框架的高度固定在34px,但内容高度与显示器大小和页面内容有关。我尝试用jQuery计算框架的高度,然后减去高度ou 34,然后在iframe上设置它,但没有效果。 为了提醒大家一切正常,请执行setSizes math函数

框架页面上的HTML

<div id="radiodiv">
<iframe src="" id="radioiframe" height="34px" width="100%" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" scrolling="no" allowtransparency="true" style="display:none;"></iframe></div>

<div id="contentdiv">   
<iframe src="home2.php" id="content" name="content" height="100%"  width="100%" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" vspace="0" hspace="0"></iframe></div>

<script type="text/javascript">
function setSizes() {
var containerHeight = $("#content").height();
document.getElementById('content').height = containerHeight - 34;
}
</script>

如何设置contentdiv的样式,并将溢出设置为滚动

<div id="contentdiv" style="overflow: scroll;">   
    <iframe src="home2.php" id="content" name="content" height="200px"  width="100%" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" vspace="0" hspace="0"></iframe>
</div>

只是一个想法。

这不起作用,因为div没有得到框架页面的高度,但它得到了父级的高度。我用一些代码使它工作了,只是稍微调整了一下,但你知道为什么在Chrome中它会减少一点底部吗?在IE和firefox中,它是完美的。$document.ready函数autoHeight{var docHeight=$document.height;var radioHeight=parent.$radioframe.height;if docHeight{var contentHeight=docHeight-radioHeight;parent.$'content'.css{'height':contentHeight+'px'};};我将帧中的高度设置为1,以便它尽快进行计算,然后如果高度发生变化,它将进行减法并平滑进行
<div id="contentdiv" style="overflow: scroll;">   
    <iframe src="home2.php" id="content" name="content" height="200px"  width="100%" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" vspace="0" hspace="0"></iframe>
</div>
function ShowSaburi() {
// your methods
// add this
setContentHeight();
}

function setContentHeight() {
   var docHeight = $(document).height();
   if (docHeight){
      var contentHeight = docHeight - 40;
      $('#contentdiv').css({'height': contentHeight+ 'px'});
   }
}