2022-11-16 23:04:45 +00:00
|
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
|
|
|
2022-11-17 00:25:18 +00:00
|
|
|
const inputFile = document.querySelector('#input__img');
|
|
|
|
const labelInput = document.querySelector('.label-input');
|
|
|
|
|
2022-11-17 00:52:09 +00:00
|
|
|
const textLabelInput = "Imagem";
|
2022-11-17 00:25:18 +00:00
|
|
|
|
2022-11-17 00:52:09 +00:00
|
|
|
labelInput.innerHTML = textLabelInput;
|
2022-11-17 00:25:18 +00:00
|
|
|
|
|
|
|
inputFile.addEventListener('change', (e) => {
|
|
|
|
const inputTarget = e.target;
|
|
|
|
const file = inputTarget.files[0];
|
|
|
|
|
|
|
|
if (file) {
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
|
|
|
reader.addEventListener('load', (e) => {
|
|
|
|
const readerTarget = e.target;
|
|
|
|
|
|
|
|
const img = document.createElement('img');
|
|
|
|
img.src = readerTarget.result;
|
|
|
|
img.classList.add('img-result');
|
|
|
|
|
|
|
|
labelInput.appendChild(img);
|
|
|
|
|
|
|
|
});
|
2022-11-17 00:52:09 +00:00
|
|
|
|
2022-11-17 00:25:18 +00:00
|
|
|
reader.readAsDataURL(file);
|
|
|
|
labelInput.innerHTML = "";
|
2022-11-17 00:52:09 +00:00
|
|
|
labelInput.style.border = "none";
|
|
|
|
|
2022-11-17 00:25:18 +00:00
|
|
|
|
|
|
|
}else {
|
2022-11-17 00:52:09 +00:00
|
|
|
labelInput.innerHTML = textLabelInput;
|
2022-11-17 00:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2022-11-16 23:04:45 +00:00
|
|
|
|
|
|
|
});
|