как я могу перетащить свою фотографию в другую папку для показа после предварительного просмотра моей фотографии? - PullRequest
0 голосов
/ 16 мая 2019

я хотел бы сделать так, чтобы предварительный просмотр стал перетаскиваемым и переместился в другое раскрывающееся меню

make img source "" перемещает (перетаскивает) в другую область выпадающего списка

<script>
function handleFiles(files) {
  for (let i = 0; i < files.length; i++) {
    const file = files[i];

    if (!file.type.startsWith('image/')){ continue }

    const img = document.createElement("img");
    img.classList.add("obj");
    img.file = file;
    preview.appendChild(img); // Assuming that "preview" is the div output where the content will be displayed.

    const reader = new FileReader();
    reader.onload = (function(aImg) { return function(e) { aImg.src = e.target.result; }; })(img);
    reader.readAsDataURL(file);
  }
}```
</script>

Как я могу перейти в другую область после того, как моя картинка находится в предварительном просмотре

1 Ответ

0 голосов
/ 16 мая 2019

Используя java-скрипт, отобразите изображение в div, которое называется «Предварительный просмотр». и включите функцию перетаскивания изображения в контейнер Drop Box с помощью функции jQuery dragggable & droppable .

enter image description here

window.onload = function(){
	
	//For example put some image in array
	arrayfile = ['https://www.w3schools.com/html/pic_trulli.jpg', 'https://www.w3schools.com/html/img_girl.jpg'];
	handleFiles(arrayfile);
	function handleFiles(files) {
	  for (let i = 0; i < files.length; i++) {
		const file = files[i];
		var img = document.createElement("IMG");
		img.setAttribute("src",file);
		img.classList.add("child");
		img.setAttribute("width", "304");
		img.setAttribute("height", "228");
		img.setAttribute("alt", "image alt");
		img.setAttribute("width", "100");
        img.setAttribute("height", "100");
		//append the image in preview div
		document.getElementById('preview').appendChild(img); 
	  }
	}
	
	
	//Use the jquery draggable & droppable function
	$(".child").draggable({
		revert: true
	});

	//use container to drop the image
	$(".container").droppable({
    accept: '.child',
    drop: function(event, ui) {
	 ui.helper.data('dropped', true);
	 $(this).append($(ui.draggable));
    }

  });
  
}
.container{
border:1px solid grey;
    width: 250px; /*can be in percentage also.*/
    height: 250px;
    margin: 0px auto;
    padding: 10px;
    position: relative;
    text-align:center;
	float:left;
	margin-left:20px;
	
}
.child {
    padding: 2px;
    border: 1px solid black;
    margin: 5px;
}
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
	
	<!-- Preview div---->
	<div id="preview" class="container" target="child1">
	</div>
		
	<!-- container to drop the Preview Image -->
    <div class="container">

    </div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...