📌  相关文章
📜  如何获取画布的父 div 的内部宽度 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:32.327000             🧑  作者: Mango

代码示例1
var canvas = document.querySelector('canvas');
fitToContainer(canvas);

function fitToContainer(canvas){
  // Make it visually fill the positioned parent
  canvas.style.width ='100%';
  canvas.style.height='100%';
  // ...then set the internal size to match
  canvas.width  = canvas.offsetWidth;
  canvas.height = canvas.offsetHeight;
}