Javascript 如何保持<;部门>;当用户在Mozilla Firefox上放大和缩小页面时大小不变

Javascript 如何保持<;部门>;当用户在Mozilla Firefox上放大和缩小页面时大小不变,javascript,jquery,html,css,firefox,Javascript,Jquery,Html,Css,Firefox,我已经能够在Chrome、Safari和Opera mini上的所有缩放级别上设置DIV content常量,但我无法让Mozilla在浏览器本身上应用相同的JavaScript代码来设置DIV常量。当我将缩放级别设置为100%以上时,它会将chrome、safari和opera mini上的所有div内容设置为正常内容,但在Mozilla上则相反,因此我想知道如何将其设置为与其他web浏览器相同,Mozilla浏览器是否支持下面JavaScript命令中的语法,因为这让我发疯了 //scri

我已经能够在Chrome、Safari和Opera mini上的所有缩放级别上设置DIV content常量,但我无法让Mozilla在浏览器本身上应用相同的JavaScript代码来设置DIV常量。当我将缩放级别设置为100%以上时,它会将chrome、safari和opera mini上的所有div内容设置为正常内容,但在Mozilla上则相反,因此我想知道如何将其设置为与其他web浏览器相同,Mozilla浏览器是否支持下面JavaScript命令中的语法,因为这让我发疯了

 //script to set DIV content constant as user zooms. NOT WORKING ON MOZILLA
 <script>
   function flostingDiva() {
     // How much the screen has been zoomed.
     var zoomLevel = screen.width / window.innerWidth;
     // By what factor we must scale the div for it to look the same.
     var inverseZoom = window.innerWidth/screen.width;
     // The div whose size we want to remain constant.
     var h = document.getElementById("scrollbox4");    

     // This ensures that the div stays at the top of the screen at all times. For some 
     // reason, the top value is affected by the zoom level of the Div. So we need to
     // multiple the top value by the zoom level for it to adjust to the zoom. 
     h.style.top = ((window.pageYOffset + 5) * zoomLevel).toString() + "px";

     // This ensures that the window stays on the right side of the screen at all times. 
     // Once again, we multiply by the zoom level so that the div's padding scales up.
     h.style.paddingLeft = ((window.pageXOffset + 5) * zoomLevel).toString() + "px";

     // Finally, we shrink the div on a scale of inverseZoom.
     h.style.zoom = inverseZoom;    
  }

  // We want the div to readjust every time there is a page load event:
  $(function() {
    floatingDiva();
  });        
</script>
//在用户缩放时设置DIV content常量的脚本。不在MOZILLA上工作
函数flostingDiva(){
//屏幕放大了多少。
var zoomLevel=screen.width/window.innerWidth;
//通过什么因素,我们必须缩放div,使其看起来相同。
var inverseZoom=window.innerWidth/screen.width;
//我们希望其大小保持不变的div。
var h=document.getElementById(“scrollbox4”);
//这样可以确保div始终位于屏幕顶部
//原因是,顶部值受Div的缩放级别影响。因此我们需要
//将顶部值乘以缩放级别,使其适应缩放。
h、 style.top=((window.pageYOffset+5)*zoomLevel.toString()+“px”;
//这可确保窗口始终位于屏幕的右侧。
//我们再次乘以缩放级别,以使div的填充向上缩放。
h、 style.paddingLeft=((window.pageXOffset+5)*zoomLevel.toString()+“px”;
//最后,我们在inverseZoom的尺度上收缩div。
h、 style.zoom=inverseZoom;
}
//每次发生页面加载事件时,我们都希望div重新调整:
$(函数(){
浮动diva();
});        

缩放在Firefox中不起作用。您可以改为使用此代码:

h.style.MozTransform = "scale(" + inverseZoom + ")";
h.style.MozTransformOrigin = ((window.pageYOffset + 5) * zoomLevel).toString() + " " + ((window.pageXOffset + 5) * zoomLevel).toString();
还可以使用图元将初始比例设置为1,并防止用户放大:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />


避免模棱两可的函数名,它们更难阅读,我们在浏览代码时不知道它们会做什么。大多数错误源于错误的编码方式。FF根据Try使用
window.screen.width
afaik
zoomLevel=window.devicePixelRatio
。但也请看。@DarkMukke首先我没有检测到缩放级别,其次它在chrome、Safari和Opera上工作没有任何问题,这段代码,所以我知道Firefox一定有修复程序。我看到一个输入错误函数flostingDiva()