Skip to content Skip to sidebar Skip to footer

Selecteddraggable In Image Preview

I would like to know how I can do selectedDraggable on my image preview what I want to do is intergrade 'selectedDraggable' to image preview so I can be able to delete any image I

Solution 1:

This code $(this).parent() will return #draggableHelper, but the images are appended to body, this means $(this).parent().find('img') will by empty. To solve that you can append your images to #draggableHelper:

var inputLocalFont = document.getElementById("image-input");
inputLocalFont.addEventListener("change", previewImages, false);

functionpreviewImages() {
  var fileList = this.files;

  var anyWindow = window.URL || window.webkitURL;

  for (var i = 0; i < fileList.length; i++) {
    var objectUrl = anyWindow.createObjectURL(fileList[i]);
    var imgEl = $('<img src="' + objectUrl + '" />');
    $('<div class="preview-area"/>').append('<a class="remove-img"> &times; </a>').append(imgEl).appendTo('body')
      .draggable();
    //^ change to this
    imgEl.load(function() {
      $(this).resizable();
    });
    window.URL.revokeObjectURL(fileList[i]);
  }


}
$('body').on('click', '.remove-img', function(e) {
  e.stopPropagation();
  var parent = $(this).parents('.preview-area');
  parent.find('img').resizable('destroy');
  parent.draggable('destroy').remove();
});
.remove-img {
  position: relative;
  top: 0px;
  right: 0px;
  width: 25px;
  height: 25px;
  background-color: #f00;
  font-size: 22px;
  color: #fff;
  text-align: center;
  display: block;
  cursor: pointer;
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><scriptsrc="//cdnjs.cloudflare.com/ajax/libs/knockout/2.3.0/knockout-min.js"></script><linkrel="stylesheet"href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /><scriptsrc="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script><linkrel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"><scriptsrc="//code.jquery.com/jquery-1.10.2.js"></script><scriptsrc="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script><scriptsrc="http://circletype.labwire.ca/js/circletype.js"></script><scriptsrc="http://tympanus.net/Development/Arctext/js/jquery.arctext.js"></script><divid="draggableHelper"style="display:inline-block"><inputtype="file"class="dimmy"id="image-input"multiple /><spanid="image"class="preview-area"style="height:100px; width:200px;"></span></div>

Post a Comment for "Selecteddraggable In Image Preview"