<link rel="stylesheet" href='media700.css' media="screen and (max-width:700px)">
var a = window.outerWidth;
console.log(a); // 711
スタイルシートmedia700
を切り替える瞬間のJavaScript計算は711pxなく700px窓幅に使用さよれ。
<link rel="stylesheet" href='media700.css' media="screen and (max-width:700px)">
var a = window.outerWidth;
console.log(a); // 711
スタイルシートmedia700
を切り替える瞬間のJavaScript計算は711pxなく700px窓幅に使用さよれ。
窓枠、スクロールバーです。
700px以下になると、CSSのメディアクエリとjsを使った背景の変更を使用してテキスト700pxが表示されます。
デモを全画面表示でサイズ変更します。
$(window).on("resize", function() {
var innderWidth = $(this).innerWidth();
$("span").text(innderWidth + "px");
if (innderWidth <= 700) {
$("body").css("background-color", "gold");
} else {
$("body").css("background-color", "");
}
});
body {
margin: 0;
}
p {
margin: 0;
background-color: dodgerblue;
font-size: 3em;
}
@media (max-width: 700px) {
body::after {
font-size: 10em;
content: "700px";
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>
Window inner width: <span></span>
</p>
重複します。http://stackoverflow.com/questions/11309859/css-media-queries-and-javascript-window-width -do-not-match – brianyang
Googleはjavascriptのデバイスとビューポートのサイズについてこの[リンク](http://ryanve.com/lab/dimensions/)を思いついた。たぶん便利です... – michaPau