Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
How to prevent dragging of an <image> element inside a <svg>?

I am building an editor that uses an SVG element as the canvas. It provides custom drag-and-drop behavior to drag elements inside the svg around. However, when I try to drag an <image> tag, the native browser drag behavior where you're dragging a "ghost" of the image kicks in. How do I stop it?

I tried setting user-select: none in CSS, which does prevent selecting text but not dragging the image. I tried setting the HTML draggable="false" property, which has no effect in SVG. I even tried to cancel the ondragstart event, which doesn't seem to fire at all.

<svg>
  <image draggable="false" style="user-select: none;" ondragstart="return false" href="https://wehles.files.wordpress.com/2020/05/opamp.png?w=147"></image>
</svg>

JSfiddle: https://jsfiddle.net/1dnfpray/

How do I prevent the image from being dragged, so that I can implement my own drag behavior?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you cancel the mousedown event, the drag is prevented:

<svg>
  <image draggable="false" style="user-select: none;" onmousedown="return false" href="https://wehles.files.wordpress.com/2020/05/opamp.png?w=147"></image>
</svg>

You'll need to handle that event anyway, if you want to implement your own dragging behaviour.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda