How do you create auto resizing a iframe when you make your browser smaller?

做~自己de王妃 提交于 2020-01-03 04:33:09

问题


Does anyone know of a way to auto resize an iframe when you make your browser smaller??


回答1:


You can attach a handler to the window.onresize event, and then resize your IFRAME appropriately.

I prefer jQuery:

$(window).resize(function() {
  $('IFRAME').width($(window).width());

});



回答2:


One option is to specify the <iframe> size in percent.




回答3:


Haven't tried it but I guess you could use a percentage width instead of a fixed width. In that case you should probably add a minimum width and height as well, to avoid that it is getting too small:

iframe
{
   width: 50%;
   height: 50%;
   min-width: 300px;
   min-height: 300px;
}



回答4:


You could as well use this.

Basically it makes use of callResize() in Child page and resizeIframe() in Parent page.




回答5:


You can also do this without JavaScript if you'd like using CSS Media Queries. See this example here:

http://ie.microsoft.com/testdrive/HTML5/CSS3MediaQueries/Default.html

They are often used for "responsive design".



来源:https://stackoverflow.com/questions/9432010/how-do-you-create-auto-resizing-a-iframe-when-you-make-your-browser-smaller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!