简体   繁体   English

缩放时如何防止iframe调整大小

[英]How to prevent an iframe from re-sizing when zooming

I've read similar issues on this but no one seems to have an answer. 我已经读过类似的文章,但是似乎没人能找到答案。 I have an iframe where I am loading an image. 我有一个要加载图像的iframe。 When I zoom the iframe becomes bigger or smaller. 缩放时,iframe会变大或变小。 Is there a way to prevent the iframe from zoooming or a way to keep the ratio when zooming? 有没有一种方法可以防止iframe发生缩放或在缩放时保持该比例?

I got it working for an image but can seem to get it to work for when I use an iframe 我将其用于图像,但是当我使用iframe时似乎可以使其正常工作

JS JS

var iframeDimensions = document.getElementById('mobile-iframe');
var iwidth = iframeDimensions.clientWidth;
var iheight = iframeDimensions.clientHeight;



$(window).resize(function(){

    var device = detectZoom.device();

    newWidth = iwidth / device;
    newHeight = iheight / device;


    $(iframeDimensions).attr('width', newWidth);
    $(iframeDimensions).attr('height', newHeight);

    var winW = document.body.offsetWidth;


    console.log('zoom level: '+device);
    console.log('new width: '+newWidth+'px');
    console.log('new height: '+newHeight+'px');
    console.log('offsetWidth '+winW);
    console.log('scale '+ winW / newWidth);




    //$('iframe').css('-webkit-transform', 'scale(' + (device + ", " + device) + ')')
    $('iframe').width();
   //$('iframe').css('-webkit-transform', 'scale(1)');



});

HTML HTML

<iframe id="mobile-iframe" src="https://www.google.com/logos/doodles/2013/maria-callas-90th-birthday-6111044824989696-hp.jpg" width="534" height="210" frameborder="0"></iframe>

Solution with JS: JS解决方案:

take a look at this How to detect page zoom level in all modern browsers? 看看这个如何在所有现代浏览器中检测页面缩放级别? for example to detect the browser zoom level and then multiply the width and height of your iframe with the inverse value so in the end they visually stay the same. 例如,检测浏览器的缩放级别,然后将iframe的宽度和高度乘以倒数值,以便最终它们在视觉上保持不变。

Example: zoom level is 1 (Standard): width: 100px; 示例:缩放级别为1(标准):宽度:100像素; height: 50px; 高度:50px; zoom level is 2: width: 50px; 缩放级别为2:宽度:50像素; height: 25px; 高度:25px; -> Browser shows it double the size so it stays the same ->浏览器显示它的大小增加一倍,因此保持不变

just added: I still wouldn't recommend doing it due to usability ;) 刚刚补充:由于可用性,我仍然不建议这样做;)

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

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