Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
Add dot on canvas grid

This is a canvas grid with the coordinates labelled when you click on the grid at here May I ask how to place a red dot on the grid as shown in the picture? Please provide a demo for understanding:)

enter image description here

function showCoords(event) {
    var x = event.clientX - 10;
    var y = event.clientY - 10;
    var coords = "X coordinates: " + x + ", Y coordinates: " + y;
    document.getElementById('showCoords').innerHTML = coords;

  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

OK so first you may create a CSS class for the red dots:

  <style>
    .red-dot {
      position:absolute; 
      width:5px; 
      height:5px;
      background:red;
    }
  </style>

Then try to modify the showCoords() method:

function showCoords(event) {
    // Calculate the position of the nearest grid intersection:
    var x = (Math.floor(event.clientX/10) * 10) - 2;
    var y = (Math.floor(event.clientY/10) * 10) - 2;
    var coords = "X coordinates: " + x + ", Y coordinates: " + y;
    document.getElementById('showCoords').innerHTML = coords;
    // Create a new red dot:
    let newDot = document.createElement('span');
    // Add the CSS class:
    newDot.className = 'red-dot';
    // Set coordinates:
    newDot.style.top = y + 'px';
    newDot.style.left = x + 'px';
    // Add the new element to the end of the body:
    document.body.appendChild(newDot);
  }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda