ページ全体にわたってHTML canvas
を拡張しようとしましたが、jQuery width()
およびheight()
関数は、垂直スクロールバーと水平スクロールバーを作成しています。スクロールバーを作成せずにビューポートの高さと幅を取得する方法は?
HTML
<body>
<canvas id="bg_canvas" width="" height=""></canvas>
</body>
jQueryの
// Expand canvas to full viewport size
var vp_width = window.clientWidth;
var vp_height = window.clientHeight;
$("#bg_canvas").css({
"width" : vp_width,
"height" : vp_height
});
// Canvas Drawing
var canvas = document.getElementById("bg_canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle="#cbf7ed";
ctx.fillRect(100,100,vp_width,100);
はまた、Javascriptのwindow.innerheight
とwindow.innerWidth
を試してみましたが、それはまた、スクロールバーを作成します。
は '(/ a)は正しい値を返すvp_width'ですか? CSSを使ってみることもできます: '#bg_canvas {width:100vw; height:100vh;}'。 – Alvaro