Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!