Skip to content

Instantly share code, notes, and snippets.

@kobitoDevelopment
Last active June 20, 2022 10:41
Show Gist options
  • Select an option

  • Save kobitoDevelopment/a76c6efe32fcad6d12a7c7f475489f9c to your computer and use it in GitHub Desktop.

Select an option

Save kobitoDevelopment/a76c6efe32fcad6d12a7c7f475489f9c to your computer and use it in GitHub Desktop.
(function () {
const setSize = 360; // 希望のviewport下限を設定
const viewport = document.querySelector("meta[name='viewport']");
function adjustViewport() {
/*
三項演算子(条件演算子)
condition ? exprIfTrue(trueに変換できる値) : exprIfFalse(falseに変換できる値)
*/
const value = window.outerWidth > setSize ? "width=device-width,initial-scale=1" : "width=" + setSize;
if (viewport.getAttribute("content") !== value) {
viewport.setAttribute("content", value);
}
}
addEventListener("resize", adjustViewport);
adjustViewport();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment