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

194
Views
Cropper no se puede destruir dos veces o más

cropper se destruye al hacer clic en el botón "cancelar", si subo otra imagen, la segunda vez que se presiona el botón "cancelar" el elemento DOM cropper no se elimina y las variables aún están presentes, si elimino manualmente el elemento DOM cropper puedo veo la interfaz de usuario de recorte para todas las imágenes que sigo cargando, pero tan pronto como trato de recortar, por ejemplo, la tercera imagen cargada, aparece este error:

Mensaje de error

Causa del error

Aquí está mi código js/Jquery para manejar cropper

 const image_input = document.querySelector("#heads-img-input"); image_input.addEventListener("change", function() { document.getElementById("overlay").style.display = "block"; const reader = new FileReader(); reader.addEventListener("load", () => { const uploaded_image = reader.result; document.querySelector("#crop-image").setAttribute("src", `${uploaded_image}`); const image = document.getElementById('crop-image'); const cropper = new Cropper(image, { aspectRatio: 1 / 1, viewMode: 2, movable: false, zoomable: false, zoomOnTouch: false, cropBoxResizable: false, toggleDragModeOnDblclick: false, scalable: false, rotatable: false, guides: false, background: false, data:{ //define cropbox size width: 400, height: 400, } }) $result = jQuery('#result'); jQuery('#crop-btn').click(function() { // Get a string base 64 data url var croppedImageDataURL = cropper.getCroppedCanvas().toDataURL("image/png"); $result.append( jQuery('<img>').attr('src', croppedImageDataURL) ); }); jQuery('#cancel-btn').click(function() { cropper.destroy(); document.querySelector("#crop-image").removeAttribute("src"); document.getElementById("overlay").style.display = "none"; }); }); reader.readAsDataURL(this.files[0]); });

});

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!