canvas - 当我有响应的画布宽度和高度时,html5画布的问题无法呈现矩形
问题描述
当我在代码中显示画布示例的响应宽度和高度时,html5 画布的问题无法呈现矩形。如果我删除它呈现矩形的代码的响应部分,但没有呈现矩形并且无法理解为什么
const canvas = document.querySelector('canvas')
const ctx = canvas.getContext('2d')
canvas.width = innerWidth
canvas.height = innerHeight - 100
ctx.strokeRect(50, 50, 50, 50);
// without this part of code it renders rectangle but with it rectangle is not rendered
window.addEventListener('resize', resizeWindow)
function resizeWindow() {
canvas.width = innerWidth
canvas.height = innerHeight - 100
}
resizeWindow()
解决方案
推荐阅读
- angular - ng-select 在移动设备上具有更好的渲染效果
- java - 如何在原生 android 中嵌入多个统一模块?
- android - 尽管数据库中有值,但调试器在 Android Studio 中显示空值
- python - tkinter:AttributeError:'str'对象没有属性'tk'
- javascript - jQuery点击
- 下拉选项
- json - 在 Excel VBA 中解析 JSON 并按键访问数组
- aem - 用于查找所有匹配标签的 AEM TagManger 方法
- python - Flask - 使用数据库中的大量数据重定向到同一页面
- android - 以编程方式更新 APK 从内容 URI 暂存 apk 时出错
- python - 基于 Python 中前一行的值填充列的行的矢量化解决方案