Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
Why does my browser render double the height value?

If run below code and DOM, my browser is renderred double all height value.

First, I tested below code in about:blank.

In html:

...
<canvas id="canvasArea" style="
    width: 500px;
    height: 500px;
    background-color: E0E0E0;
"></canvas>
...

and In js:

let cv = document.getElementById("canvasArea");
let cvArea = cv.getContent('2d');

cvArea.fillRect(10, 10, 50, 50); // I was thinking this Rect is square
cvArea.fillRect(60, 10, 50, 25); // and this Rect is long rectangle

I was thinking first rect will be draw square. But first is long rectangle.

Why does this happen?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

JS Canvases are not aware of dimensions set by CSS.

Use HTML attributes or set using JS.

let cv = document.getElementById("canvasArea");
let cvArea = cv.getContext('2d');

cvArea.fillRect(10, 10, 50, 50); // I was thinking this Rect is square
//cvArea.fillRect(60, 10, 50, 25); // and this Rect is long rectangle
<canvas id="canvasArea" width="500" height="500" style="
    background-color: #E0E0E0;
"></canvas>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda