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

171
Views
compruebe si el círculo está suspendido HTML5 Canvas

Quiero hacer un estado flotante para el círculo en el lienzo. Esto es lo que tengo

Código:

 let canvas = document.getElementById('canvas') let ctx = canvas.getContext('2d') let circle = { x: 100, y: 100, r: 30 } ctx.beginPath() ctx.arc(circle.x, circle.y, circle.r, 0, Math.PI * 2) ctx.strokeStyle = "#aaa" ctx.lineWidth = 3 ctx.stroke() ctx.closePath() this.canvas.addEventListener('mousemove', e => { let rect = this.canvas.getBoundingClientRect() let position = { x: e.clientX - rect.left, y: e.clientY - rect.top, } if(position.x > circle.x - circle.r && position.x < circle.x + circle.r && position.y < circle.y + circle.r && position.y > circle.y - circle.r ) { this.canvas.style.cursor = 'pointer' } else { this.canvas.style.cursor = 'default' } })
 <canvas id="canvas" />

Pero en el código anterior, flotará como si el círculo fuera un cuadrado.

ingrese la descripción de la imagen aquí

Aplicará el estado de desplazamiento fuera del círculo, en cada esquina del cuadrado. Creo que es debido a las condiciones if en este fragmento de código:

 if(position.x > circle.x - circle.r && position.x < circle.x + circle.r && position.y < circle.y + circle.r && position.y > circle.y - circle.r ) { this.canvas.style.cursor = 'pointer' }

¿Alguien tiene una solución para hacer que el estado de desplazamiento funcione exactamente dentro del círculo?

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!