简体   繁体   English

Firefox中的CSS转换比例问题

[英]css transform scale issue in firefox

I am trying to make a website scale based on the document size. 我正在尝试根据文档大小来调整网站规模。

So when the document is 0px<1024px there should be a responsive design. 因此,当文档为0px <1024px时,应该有一个响应式设计。 This is strait forward with css media query. 这是CSS媒体查询的难题。 On the scale 1024px<1950px the "normal" design should be shown. 在1024px <1950px的比例尺上,应显示“正常”设计。 Also this is pretty easy and this two dimentions working very fine. 同样,这非常容易,并且这两个尺寸非常好。

Now I want that, when the document is >1950px, the scale is going up. 现在我想要的是,当文档> 1950px时,比例正在上升。 So that when for example the screen is 2000px the website has a transform scale(2). 因此,例如当屏幕为2000px时,网站将具有转换比例(2)。

For this I came up with this little solution: 为此,我想出了这个小解决方案:

$(document).ready(larg);
$(window).resize(larg);
function larg(){
    var startResizing = 1950;
    var documentWidth = $(window).width();
    console.log("documentWidth: "+documentWidth);
    if(documentWidth > startResizing){
        var scale = (documentWidth - startResizing) / 2000;
        var roundTwoDecimals = Math.round(scale * 100) / 100;
        scale = 1 + roundTwoDecimals;
        console.log(documentWidth +"-"+ startResizing+"="+(documentWidth - startResizing));
        console.log(scale);

        $("html").css("zoom", scale); // IE
        $("html").css("-moz-transform", "scale("+scale+")"); // Firefox
        $("html").css("-moz-transform-origin", "0 0");
        $("html").css("-o-transform", "scale("+scale+")"); // Opera
        $("html").css("-o-transform-origin", "0 0");
        $("html").css("-webkit-transform", "scale("+scale+")"); // Safari and Chrome
        $("html").css("-webkit-transform-origin", "0 0");
        $("html").css("transform", "scale("+scale+")"); // Standard Property
        $("html").css("transform-origin", "0 0");
    }else{ // Reset
        $("html").css("zoom", ""); // IE
        $("html").css("-moz-transform", ""); // Firefox
        $("html").css("-moz-transform-origin", "");
        $("html").css("-o-transform", ""); // Opera
        $("html").css("-o-transform-origin", "");
        $("html").css("-webkit-transform", ""); // Safari and Chrome
        $("html").css("-webkit-transform-origin", "");
        $("html").css("transform", ""); // Standard Property
        $("html").css("transform-origin", "");
    }
}

In Chrome this is working fine. 在Chrome中可以正常运行。 But in Firefox there is one big problem: 但是在Firefox中存在一个大问题:
The scaling is done also on the X axis and a horizontal scroll is generated. 在X轴上也进行缩放,并生成水平滚动。 And my html/body tag that normally has 100% width does not fit in the window anymore. 而且我通常具有100%宽度的html / body标签不再适合窗口。 So the user has to scroll horizontal and that should be not the case (in chrome everything is fine). 因此,用户必须水平滚动,而事实并非如此(在Chrome中一切正常)。
What am I doing wrong? 我究竟做错了什么?

EDIT 编辑
I now found out, that the complete point of view is scaled and that I have to set the width of the html tag down. 我现在发现,完整的视角已缩放,并且我必须将html标签的宽度减小。 So instead of usind 100% I not calculate the width with 100 / newScale and this is working fine now :) 因此,不是使用usind 100%,我不使用100 / newScale计算宽度,现在可以正常工作了:)

To change your CSS this way is really bad practice. 以这种方式更改CSS确实是一种不好的做法。 You might want to take a look at CSS media queries , where you can do this in a better practice and easier. 您可能需要看一下CSS媒体查询 ,可以在其中更好地实践和轻松进行此操作。 This way of doing responsive scaling is supported in all modern browsers. 所有现代浏览器都支持这种进行响应式缩放的方法。

Js (jQuery) is a bad practice for scaling website (wait for the website to be fully loaded, then change its size?) Js(jQuery)是缩放网站的不良做法(等待网站完全加载,然后更改其大小?)

Use @media insead: 使用@media insead:

@media (max-width:1023px) {
   /* scaled down */
   .body {transform: scale (50%); }
}

@media (min-width:1024px) and (max-width:1950px) {

}
@media (min-width:1951px) {
    /* scaled up */
    .body {transform: scale (200%); }
}

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

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