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

251
Vistas
How can place marker on an image using JavaScript that doesn't change after zooming

this is our code but this code is give me the coordinates according to the body relative but when i change the zoom then its gives me different values i want to get coordinates and save in my backend that cannot be change this is my code

function FindPosition(oElement) {
    console.log(oElement);
    console.log(oElement.pageX);
    if (typeof (oElement.offsetParent) != "undefined") {
      for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
        posX += oElement.offsetLeft;
        posY += oElement.offsetTop;
      }
      return [posX, posY];
    }
    else {
      return [oElement.x, oElement.y];
    }
  }

  function GetCoordinates(e) {
    var PosX = 0;
    var PosY = 0;
    var ImgPos;
    ImgPos = FindPosition(myImg.current);
    // console.log(document.documentElement.scrollTop);
    console.log(myImg);
    if (!e) {
      var e = window.event
    };
    if (e.pageX || e.pageY) {
      PosX = e.pageX;
      PosY = e.pageY;
    }
    else if (e.clientX || e.clientY) {
      PosX = e.clientX + document.body.scrollLeft
        + document.documentElement.scrollLeft;
      PosY = e.clientY + document.body.scrollTop
        + document.documentElement.scrollTop;
    }
    PosX = PosX - ImgPos[0];
    PosY = PosY - ImgPos[1];

  }

here is jsx which is written in react js

      <div className="map" ref={"Here is map image"} onMouseDown={GetCoordinates}>
        <img className='mapImage' src={map} alt="" />
        <RoomIcon className="markerIcon" />
      </div>

this is the css code


.map {
  /* height: 100px; */
  text-align: center;
  margin: auto;
  /* overflow: scroll; */
  margin-top: 18px;
  position: relative;
}

.mapForm .map img {
  margin-top: 18px;
  /* width: ; */
  /* width: 1900px; */
  /* zoom: 150%; */
}

.mapImage {
  width: 600px;
  /* zoom: 600%; */
}

.markerIcon {
  z-index: 5;
  position: absolute;
  color: #e24e40;
  left: 30px;
  top: 30px;
}

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