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

161
Vistas
Change drag image inside a DragEnter event

I'm trying to define the image that appears when I drag an element inside my page. I saw how to do it with DataTransfer.setDragImage() in that link but with me it is not working. There are two differences between my code and the example:

  • I'm trying to make this change through the DragEnter event while the link is done in DragStart;
  • The image to be dragged will be in the user's file explorer, not in the HTML document.

I already did a test and the image is being generated correctly. This is the code responsible for this functionality:

function handleDragEnter(event)
{
    const img = new Image;
    const reader = new FileReader;
    reader.readAsDataURL((new Blob(icon(faPhotoFilmMusic).html, { type: 'image/svg+xml' })));
    reader.addEventListener('load', () => {
        img.src = reader.result;
        event.dataTransfer.setDragImage(img, 10, 10);
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I think the problem is in missing parentheses:

function handleDragEnter(event)
{
    const img = new Image(); // <=== change this 
    const reader = new FileReader(); // <=== change this 
    reader.readAsDataURL((new Blob(icon(faPhotoFilmMusic).html, { type: 'image/svg+xml' })));
    reader.addEventListener('load', () => {
        img.src = reader.result;
        event.dataTransfer.setDragImage(img, 10, 10);
    });
}
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