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

108
Views
Mover un div de texto por jquery

Tengo un div que contiene algo de texto y quiero poder mover ese div cuando hago clic y mantengo presionado el botón izquierdo del mouse y cuando se cambia la ubicación del cursor del puntero, la ubicación del div también cambia. mi código js:

 $(() => { $(document).on("mousemove", "#div", (e) => { const x = e.pageX const y = e.pageY $("#div").css("top", y - 50) $("#div").css("left", x - 100) console.log(e.pageY) console.log(e.pageX) }) })

mi codigo html:

 <div id="div"> <span>Hello World!</span> <span>Look at Me!</span> <span>I'm Moving!</span> </div>

mi problema es que no sé usar qué evento. Quiero hacer clic y mover eventos juntos. ¿Qué debería hacer ahora?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Considere el siguiente ejemplo, basado en la siguiente demostración .

 $(function() { $("#draggable").draggable({ drag: function(event, ui) { console.log(event.pageX, event.pageY); } }); });
 #draggable { width: 150px; height: 150px; padding: 0.5em; }
 <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-3.6.0.js"></script> <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script> <div id="draggable" class="ui-widget-content"> <span>Hello World!</span> <span>Look at Me!</span> <span>I'm Moving!</span> </div>

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