简体   繁体   English

Javascript / CSS:设置(firefox)iframe的缩放级别?

[英]Javascript / CSS: set (firefox) zoom level of iframe?

I'd like to create a page with multiple iframes displaying different pages - a sort of "browse multiple pages side-by-side" type thing. 我想创建一个包含多个显示不同页面的iframe的页面 - 一种“并排浏览多页”类型的东西。 The trouble is that in doing so, the viewports are pretty small and I can only see the top-left corner of each page. 麻烦的是,这样做,视口非常小,我只能看到每个页面的左上角。

Is there a way to set the iframe to effectively do firefox's zoom-out (ctrl-minus) a few times so that the whole page is visible? 有没有办法设置iframe有效地执行firefox的缩小(ctrl-minus)几次,以便整个页面可见? I don't particularly care if the text is legible, only if I can basically see what the page looks like. 我不特别在意文本是否清晰,只要我能基本看到页面的样子。

I don't need this to be cross-browser (for my purposes it only needs to work in the latest firefox) although obviously a cross-browser solution would be preferable for the sake of anyone else who needs this and stumbles across this question. 我不需要这是跨浏览器(为了我的目的,它只需要在最新的Firefox中工作)虽然显然跨浏览器解决方案将是更好的,为了任何其他需要这个和偶然发现这个问题的人。

You can apply css transforms to iframes: 您可以将css转换应用于iframe:

iframe {
    -moz-transform: scale(0.25, 0.25); 
    -webkit-transform: scale(0.25, 0.25); 
    -o-transform: scale(0.25, 0.25);
    -ms-transform: scale(0.25, 0.25);
    transform: scale(0.25, 0.25); 
    -moz-transform-origin: top left;
    -webkit-transform-origin: top left;
    -o-transform-origin: top left;
    -ms-transform-origin: top left;
    transform-origin: top left;
    border: solid #ccc 10px;
}

http://jsfiddle.net/6QMcX/ http://jsfiddle.net/6QMcX/

The transform origin property allows it to be scaled without changing its position. transform origin属性允许在不改变其位置的情况下进行缩放。

This works for Webkit, Opera, FF and IE9 (untested). 这适用于Webkit,Opera,FF和IE9(未经测试)。 Text looks great and is still legible at very small sizes. 文字看起来很棒,并且在非常小的尺寸下仍然清晰可辨。

I got appropriate results like this (tested only in Chromium): 我得到了这样的合适结果(仅在Chromium中测试过):

CSS: CSS:

<style>
#iframe {
    -moz-transform: scale(0.25, 0.25) translate(-150%, -150%);
    -webkit-transform: scale(0.25, 0.25) translate(-150%, -150%);
    -o-transform: scale(0.25, 0.25) translate(-150%, -150%);
    transform: scale(0.25, 0.25) translate(-150%, -150%);
}
#wrapper {
    width: 256px;
    height: 230px;
}
</style>

HTML: HTML:

<div id="wrapper">
    <iframe id="iframe" width="1024" height="920" scrollbars="no"></iframe>
</div>

Maybe this helps. 也许这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM