如何动态设置iframe大小 [英] How to set iframe size dynamically

查看:742
本文介绍了如何动态设置iframe大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:

 < iframe src =html_intro.aspwidth =100%height =300> 
< p>您好SOF< / p>
< / iframe>

在这种情况下,高度根据浏览器的窗口大小而有所不同。它应该根据浏览器窗口的大小动态设置。



在任何尺寸下,iframe纵横比应该相同。如何做到这一点?

解决方案

如果您使用jquery,可以使用 $( window).height();

 < iframe src =html_intro.aspwidth = 100%class =myIframe> 
< p>您好SOF< / p>
< / iframe>

< script type =text / javascriptlanguage =javascript>
$('。myIframe')。css('height',$(window).height()+'px');
< / script>


How should I set the dimensions of an iframe dynamically, so the size is flexible for different viewport sizes?

For example:

<iframe src="html_intro.asp" width="100%" height="300">
  <p>Hi SOF</p>
</iframe>

In this case the height is different depending on the browser's window size. It should be set dynamically depending on the size of the browser window.

At any size, the iframe aspect ratio should be the same. How can this be done?

解决方案

If you use jquery, it can be done by using $(window).height();

<iframe src="html_intro.asp" width="100%" class="myIframe">
<p>Hi SOF</p>
</iframe>

<script type="text/javascript" language="javascript"> 
$('.myIframe').css('height', $(window).height()+'px');
</script>

这篇关于如何动态设置iframe大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆