Resizable does not work on dynamic image

Asked

Viewed 142 times

0

I have a tool that when the user sends any image the function resizable does not work, unlike the static image that is already on the site.

I projected online my doubt, on the following link: http://www.rafaelseverino.com/nav/resizable

If you have an alternative using jQuery, would be a good.

function doClick() {
  var el = document.getElementById("fileElem");
  if (el) {
    el.click();
  }
}

function handleFiles(files) {
    // onchange do formulário
    var d = document.getElementById("draggable");       
    var list = document.createElement("ul");        
    d.appendChild(list);
    for (var i=0; i < files.length; i++) {
        var li = document.createElement("li");
        list.appendChild(li);                       
        var img = document.createElement("img");
        img.width = 100;
        img.classList.add("ui-widget-content");
        img.classList.add("resizable");
        img.classList.add("ui-resizable");  
        img.src = window.URL.createObjectURL(files[i]);
        img.onload = function() {
            window.URL.revokeObjectURL(this.src);
        }
        li.appendChild(img);
    }
}
$(function() {
  // Redimensionameto que só está funcionando na imagem estática
    $( ".resizable" ).resizable({
        maxHeight: 194,
        maxWidth: 150,
        minHeight: 95,
        minWidth: 70
    });
});
  • 1

    Rafael, Welcome. You have lots of scripts to load on your page, hard to see everything and be sure of the problem. You can make a simplified example of your jsFiddle problem for example?

  • Thanks Sérgio, the . resizable() only works with the static image of the site, I think when a nine image is created in the DOM it does not work.

  • The part of $( ".resizable" ).resizable() has to stay within the handleFiles(files) function Right after the line li.appendchild(img); your information helped a lot, thank you.

1 answer

0


Try running . resizable() after loading the image.

  • That’s right Luís, after the code where the image is sent by the user, I added the code $( ".resizable" ).resizable(); So the resizing only works when the image is created, before that no.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.