简体   繁体   English

Window.innerwidth在浏览器调整大小时不会更新

[英]Window.innerwidth doesn't update on browser resize

When i resize the window, the window.innerwidth doesn't update. 当我调整窗口大小时,window.innerwidth不会更新。 I dont want to use jQuery. 我不想使用jQuery。

var page = window.innerWidth;
var content = document.getElementById("content");
content.style.width = page - 300 + "px";

i tried: 我试过了:

window.addEvent("resize", function() {
  console.log(window.getCoordinates().width);
});

with no avail​ 无济于事

Edit: But that still doesn't fix the window.innerwidth not changing on resize 编辑:但是那仍然不能解决window.innerwidth在调整大小时不会改变

window.onresize = function(event) {
  console.log(window.innerWidth);
};

But it will be called only after resizing is completed. 但是只有在调整大小后才能调用它。

It should rather be: 它应该是:

window.addEventListener("resize", function() {
    console.log(window.innerWidth);
});

This code works in my browser: 此代码在我的浏览器中有效:

<script>

    window.onresize = function() {    
        var widthWin = window.document.body.clientWidth;
        console.log(widthWin);         
    }

</script>

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

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