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

94
Views
por qué document no funciona.querySelectorAll — box.addEventListener no es una función

Necesito hacer un arrastrar y soltar para varias imágenes. Escribí un código de trabajo para una imagen.

 const box = document.querySelector("#box"); const offset = { x: null, y: null }; const getPosition = (e) => { const pageX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; const pageY = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; return { pageX, pageY }; }; const mousemoveHandler = (e) => { const { pageX, pageY } = getPosition(e); box.style.left = pageX - offset.x + "px"; box.style.top = pageY - offset.y + "px"; }; const mousedownHandler = (e) => { const { pageX, pageY } = getPosition(e); const { x, y } = box.getBoundingClientRect(); const leftOffset = pageX - x; const topOffset = pageY - y; offset.x = leftOffset; offset.y = topOffset; window.addEventListener("mousemove", mousemoveHandler); box.classList.add("active"); }; const mouseupListener = async () => { window.removeEventListener("mousemove", mousemoveHandler); box.classList.remove("active"); offset.x = null; offset.y = null; }; box.addEventListener("mousedown", mousedownHandler); window.addEventListener("mouseup", mouseupListener); box.ondragstart = function() { return false; };

Si cambio document.querySelector("#box") a document.querySelectorAll("#box") o document.querySelectorAll("section-one__img") para que el código funcione para todos los elementos, aparece un error Uncaught TypeError: box .addEventListener no es una función

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!