我正在使用的一种解决方案是使用容器,在该容器中放置了正在调整大小的iframe尽可能地适应可用的屏幕而不会丢失它的比例。它运作良好,但并不完全灵活:如果您希望它能够正常工作,则需要在内容页面中设置尺寸。但如果你可以用这种方式管理你的页面,我认为它几乎可以满足你的需求。
它是这样的。你创建一个基本上只有样式,调整大小脚本和iframe调用的容器html页面。你的内容进入iframe页面。
<style>
html, body
{
border: 0px;margin: 0px;
padding:0px;
}
iframe
{
display: block;
border: 0px;
margin: 0px auto;
padding:0px;
}
</style>
<script>
$(document).ready(function(e){
onResizeFn();
});
$(window).resize(function(e){
onResizeFn();
});
// this stretches the content iframe always either to max height or max width
function onResizeFn(){
var screen_ratio = 0.70 // this is your 720x500 ratio
if((window.innerHeight/window.innerWidth) > screen_ratio){
var theWidth = window.innerWidth
var theHeight = (window.innerWidth*screen_ratio);
} else {
var theHeight = window.innerHeight;
var theWidth = (window.innerHeight/screen_ratio);
}
document.getElementById("your_iframe").width = theWidth + "px"
document.getElementById("your_iframe").height = theHeight + "px"
}
</script>
// And then you call your page here
<iframe id='your_iframe' src='your_content_page' scrolling='no' frameborder='0'"></iframe>
您是否真的想要缩放内容,还是只希望窗口大小调整时页面边缘的边界增大/缩小? –
你试过bootstrap了吗? [BootStrap](http://getbootstrap.com/) –
你可以分享你已经尝试过的吗? – akshay