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

121
Views
comportamiento muy extraño al arrastrar una imagen

Estoy tratando de hacer una imagen arrastrable simple usando JS y JQuery (no jqueryUI que tiene un .draggable()...), el código funciona perfectamente cuando se mueve un div, lo mismo cuando se mueve un altImg (cuando el img src no es encontrado) pero si hay una imagen allí, actúa de forma extraña.

¡Y curiosamente al hacer clic con el botón derecho funciona bien!

 let draggable; let offset; $(document).on('mousedown', '.piece', e =>{ draggable = $(e.target); offset = {x: e.offsetX, y: e.offsetY}; }).mousemove(e=>{ if(draggable){ draggable.css({top: e.clientY - offset.y, left: e.clientX - offset.x}); } }).mouseup(()=>{ draggable = null; })
 .piece { position: absolute; top: 10px; left: 10px; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="p1" ><img class="piece" src="https://i.stack.imgur.com/UM6k6.png?s=256&g=1" alt="noimage" srcset=""></div>

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!