xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

how to get window width in javascript

how to get window width in js

How to Detect Screen Resolution with JavaScript

window

https://developer.mozilla.org/en-US/docs/Web/API/window/innerWidth

https://www.w3schools.com/jsref/prop_win_innerheight.asp

function innerFunction() {
  var w = window.innerWidth;
  var h = window.innerHeight;
  document.getElementById("demo").innerHTML = "Width: " + w + "<br>Height: " + h;
}

function outerFunction() {
  var w = window.outerWidth;
  var h = window.outerHeight;
  document.getElementById("demo").innerHTML = "Width: " + w + "<br>Height: " + h;
}

screen

https://stackoverflow.com/questions/3437786/get-the-size-of-the-screen-current-web-page-and-browser-window


window.screen.height;
window.screen.width;

viewport size / device size / document size

https://ryanve.com/lab/dimensions/


responsive viewport / viewbox

svg viewbox

small screen

const svgStr = `
<svg data-uuid="live_map_svg" id="live_map_svg" width="100%" height="100%" viewBox="0 0 1000 1000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"></svg>
`;

body.insertAdjacentHTML(`beforeend`, svgStr.trim());


https://www.tutorialrepublic.com/faq/how-to-detect-screen-resolution-with-javascript.php

https://usefulangle.com/post/190/javascript-window-width-height


原文地址:https://www.cnblogs.com/xgqfrms/p/12424229.html