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

187
Views
El lienzo se vuelve borroso en varias coordenadas (nivel de zoom del navegador < 100 %)

Estoy usando un dispositivo que tiene devicePixelRatio de 1 . En el desplazamiento, vuelvo a renderizar el lienzo agregando 1 o -1 a la posición y . Afecta la calidad del renderizado y, lo que es más importante, la posición del renderizado sigue cambiando al desplazarse. Por ejemplo, si renderizo con un espacio de 2px que está entre la línea y el texto, difiere en el desplazamiento. Esto se reproduce solo cuando se desplaza muy ligeramente.

 let canvas = document.querySelector('canvas'); let ctx = canvas.getContext('2d'); let width = 500; let height = 500; canvas.width = width * devicePixelRatio; canvas.height = height * devicePixelRatio; ctx.scale(devicePixelRatio,devicePixelRatio) let startY = 0; let lineHeight = 30; let offSet = 0.5; let padding = 2; function draw(){ for(let i=0;i<30;i++){ let y = (i*lineHeight)+(startY%lineHeight); ctx.beginPath() ctx.moveTo(250+offSet,y+offSet); ctx.lineTo(250+100+offSet,y+offSet); ctx.stroke(); ctx.font = '20px Arial'; ctx.fillText('text',250+30+offSet,y+offSet-padding); } } draw(); canvas.addEventListener('wheel',()=>{ let wheel = Math.round(event.wheelDeltaY/6); ctx.clearRect(0,0,500,500); startY += wheel; draw(); });
 canvas{ width : 500px; height : 500px; border : 1px solid; }
 <canvas></canvas>

¿Cómo puedo arreglar esto?

También puedes ver mi proyecto en codepen .

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!