Я пытался сделать html canvas полной страницей.В моем коде это предупреждает, что размер холста = размер окна, но он не показывает правильный вывод.
Вот HTML ->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas></canvas>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="main.js"></script>
</body>
</html>
CSS ->
body
{
margin: 0;
}
canvas
{
/*border: 1px solid black;*/
background: green;
}
и jquery ->
$(document).ready(function(){
$.fn.showMSG = function(){
var canvas = $("canvas");
var canvasWidth = canvas.width();
var canvasHeight = canvas.height();
var windowWidth = $(window).width();
var windowHeight = $(window).height();
canvasWidth = windowWidth;
canvasHeight = windowHeight;
var txt = "";
txt += "Canvas width/height: " + canvasWidth;
txt += "x" + canvasHeight + "\n";
txt += "Window width/height: " + windowWidth;
txt += "x" + windowHeight;
alert(txt);
}
$(window).ready(function(){
$.fn.showMSG();
});
});