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

155
Visualizações
Setting Canvas size with JQuery blurs contents

I've got a simple resize script as such:

$(`#game`).css('width', '100%');

$(window).resize(function(){
    $(`#game`).height($(`#game`).width() / 2.031);
})

(from https://stackoverflow.com/a/10750346/12359120)

The problem though, as cyberwombat said, "This will cause the content to be blurred."

The other answers on that post don't really work for my situation, as they often make the contents go offscreen.

Right now this is how blurry it is: The canvas being blurry on a large screen With the other answers: The canvas going off the screen vertically

Is there any way to make it less blurry?

Edit: The element's width and height always say 300 and 150 even though the styles say otherwise. Here is some HTML + CSS + JS that can mostly reproduce this.

const canvas = document.getElementById('game')
const ctx = canvas.getContext("2d");

$(`#game`).css('width', '100%');

$(window).resize(function() {
  $(`#game`).height($(`#game`).width() / 2.031);
})

const imageAt = ((href, x, y, sizex, sizey) => {
  var img = new Image();
  img.addEventListener('load', function() {
    ctx.drawImage(img, x, y, sizex, sizey);
  }, false);
  img.src = href
})
imageAt('https://b.thumbs.redditmedia.com/bZedgr0gq7RQBBnVYVc-Nmzdr-5vEUg4Dj8nTrMb7yA.png',0,0,25,25)
#game {
  padding-left: 0;
  padding-right: 0;
  display: block;
  padding: 0;
}

#vertical-center {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

body {
  background-color: black;
  padding: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

<div id="vertical-center">
  <canvas id="game"></canvas>
</div>

about 4 years ago · Juan Pablo Isaza
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