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

235
Views
Quiero usar funciones de cambio de tamaño y arrastre en los divs que creé

Crear código de división:

 const BtnAdd = document.querySelector(".olustur"); const DivContainer = document.getElementById("DivContainer"); BtnAdd.addEventListener("click", Olustur); function Olustur() { const newDiv = document.createElement("div"); const newResizer = document.createElement("div"); newDiv.classList.add("item") newResizer.classList.add("resizer") newResizer.classList.add("se") DivContainer.appendChild(newDiv); newDiv.appendChild(newResizer); } var elements = document.querySelectorAll(".resizer") elements.forEach(element => { element.addEventListener("mousedown",mousedown) })

Código de cambio de tamaño:

 let currentResizer; function mousedown(e){ currentResizer=e.target; isResizing = true; let prevX = e.clientX; let prevY = e.clientY; window.addEventListener("mousemove",mousemove); window.addEventListener("mouseup",mouseup); function mousemove(e){ const rect = el.getBoundingClientRect(); if(currentResizer.classList.contains('se')){ el.style.width=rect.width - (prevX - e.clientX) + "px"; el.style.height=rect.height - (prevY - e.clientY) + 'px'; } prevX=e.clientX; prevY=e.clientY; } function mouseup(){ window.removeEventListener("mousemove",mousemove); window.removeEventListener("mouseup",mouseup); isResizing=false; } }

Quiero cambiar el tamaño y arrastrar el div creado y dibujar un rectángulo como una estantería. Todos funcionan por separado pero no pude combinarlos.

Puedo crear div pero mis oyentes no funcionan.

Necesitas usar javascript puro.

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

0

Haría el cambio de tamaño usando la propiedad de cambio de tamaño de CSS y escucharía los eventos de cambio de tamaño de js. https://usefulangle.com/post/319/javascript-detect-element-resize

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!