jQuery/CSS-单击IFRAME内容内的按钮时更改IFRAME高度
jQuery/CSS - Change IFRAME Height when click on button inside the iframe content
我正在编写一个简单的HTML/jQuery脚本。现在,当我点击iframe内部的按钮时,它正在改变用按钮调用内容的iframe的高度。
看看代码:
<div id="outerdiv" style="padding:20px;border:2px solid red;">
<iframe src="http://beta.sportsdirect.bg/test/iframe.php" id="inneriframe" scrolling="no" target="_parent"></iframe>
</div>
以下是iframe.php的内容:
<HTML>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<div style="display:block;height:300px;">
<h3>The iframe content</h3>
<button type="button" id="SuperWebF1">Click me to resize the holding Iframe!</button>
</div>
<script type="text/javascript">
$("#SuperWebF1").click(function(){
$('#inneriframe', window.parent.document).animate({height:'900px'}, 500);
})
</script>
问题来了,当我试图添加这个:
<style>
#outerdiv
{
width:400px;
height:300px;
overflow:hidden;
position:relative;
border:2px solid #fff;
}
#inneriframe
{
position:absolute;
width:400px;
height:700px;
border:0px;
}
</style>
<div id="outerdiv" style="padding:20px;border:2px solid red;">
<iframe src="http://beta.sportsdirect.bg/test/iframe.php" id="inneriframe" scrolling="no" target="_parent"></iframe>
</div>
正如你所看到的,我添加了一个<style>
标记,其中我为元素outerdiv
和iframe inerriframe
添加了CSS,现在当我点击按钮时,它不会改变iframe的高度。
当我删除<style>....</style>
标记和其中的所有内容时,脚本又开始工作了。
以下是演示:http://beta.sportsdirect.bg/test/这是我还没有添加<style></style>
标签时的工作演示。
你能帮我为这些元素设置CSS并使jQuery脚本也能工作吗?
提前感谢!
当文档未完全加载到iframe
页面中时,该事件不会触发其函数。
代替:
<script type="text/javascript">
$("#SuperWebF1").click(function(){
$('#inneriframe', window.parent.document).animate({height:'900px'}, 500);
});
</script>
用途:
<script type="text/javascript">
$(document).ready(function(){
$("#SuperWebF1").on('click',function(){
$('#inneriframe', window.parent.document).animate({height:'900px'}, 500);
});
});
</script>
当页面中的所有.css
、.js
和整个文档都准备就绪时,它可以侦听click
事件。
我希望这会有所帮助?
相关文章:
- 动态增加 iframe 高度
- iframe高度100%不起作用
- 动态iframe高度-似乎需要重新加载页面
- 如何更改其内容的 Iframe 高度(两者都来自同一域)
- 同位素布局中的动态iframe高度
- 跨域中的动态 iframe 高度
- 调整外部域中的 iframe 高度
- 根据内容高度调整 iframe 高度的大小
- jQuery-在Iframe内按钮的onclick事件中更改Iframe高度
- jQuery/CSS-单击IFRAME内容内的按钮时更改IFRAME高度
- 如何在单击Iframe内部的按钮时更改Iframe高度'的内容
- JQuery根据iframe源设置iframe高度
- 如何在浏览器调整大小时调整iframe高度
- 如何更改IFRAME高度时源它's在另一个域上
- 基于内容使用Javascript设置iframe高度
- iframe高度在页面内容较长后不会缩小
- 为什么可以't从iframe内部的jquery更改iframe高度
- 根据内部内容使iframe高度动态化 - JQUERY/Javascript
- 如何根据元素高度动态调整iframe高度
- 动态调整动态更改内容高度的iFrame高度(内部说明)