let uploadButton = document.getElementById("upload-button");
let chosenImage = document.getElementById("chosen-image");
let fileName = document.getElementById("file-name");
let container = document.querySelector(".drag-area");
let submit = document.getElementById("submit");
let sub2 = document.getElementById("sub2");
let error = document.getElementById("error");
let imageDisplay = document.getElementById("image-display");
const fileHandler2 = (file, name, type) => {
if (type.split("/")[1] !== "jpeg") {
//File Type Error
container.classList.remove("dropped");
submit.classList.remove("hideit");
error.innerHTML = "<span class=\"error-m\">One or more of the selected files are invalid. Files must be .jpg/.jpeg</span>";
error.classList.remove("hideit");
setTimeout(function(){
error.innerHTML="";
error.classList.add("hideit");
},90000);
return false;
}
error.innerText = "";
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
//image and file name
let imageContainer = document.createElement("figure");
let img = document.createElement("img");
img.src = reader.result;
imageContainer.appendChild(img);
imageContainer.innerHTML += `<div id="caption">${name}</div>`;
imageDisplay.appendChild(imageContainer);
};
};
//Upload Button
uploadButton.addEventListener("change", () => {
imageDisplay.innerHTML = "";
container.classList.add("dropped");
submit.classList.add("hideit");
Array.from(uploadButton.files).forEach((file) => {
fileHandler2(file, file.name, file.type);
});
});
container.addEventListener(
"dragenter",
(e) => {
e.preventDefault();
e.stopPropagation();
const img = Array.from(e.dataTransfer.items).find(e => e.type.match('image/jpeg'))
if (img) container.classList.add("active");
else {} error.innerHTML = "<span class=\"error-m\">One or more of the selected files are invalid. Files must be .jpg/.jpeg</span>";
error.classList.remove("hideit");
},
false
);
container.addEventListener(
"dragleave",
(e) => {
e.preventDefault();
e.stopPropagation();
container.classList.remove("active");
},
false
);
container.addEventListener(
"dragover",
(e) => {
e.preventDefault();
e.stopPropagation();
const img = Array.from(e.dataTransfer.items).find(e => e.type.match('image/jpeg'))
if (img) container.classList.add("active");
else {} error.innerHTML = "<span class=\"error-m\">One or more of the selected files are invalid. Files must be .jpg/.jpeg</span>";
error.classList.remove("hideit");
},
false
);
container.addEventListener(
"drop",
(e) => {
e.preventDefault();
e.stopPropagation();
container.classList.remove("active");
container.classList.add("dropped");
submit.classList.add("hideit");
error.classList.add("hideit");
let draggedData = e.dataTransfer;
let files = draggedData.files;
imageDisplay.innerHTML = "";
Array.from(files).forEach((file) => {
fileHandler2(file, file.name, file.type);
});
},
false
);
window.onload = () => {
error.innerText = "";
};
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
img, video {
height: auto;
max-width: 100%;
}
body {
background-color: #FCFCFC;
}
.mglass {
width: 34px;
margin-left: auto;
margin-right: 10px;
opacity: 0.343;
}
.dd-t2 {
font-size: 13px;
color: #9e9e9e;
}
.hideit {
display: none !important;
}
.upl-top {
margin-bottom: 16px;
width: 80%;
display: inline-block;
}
.upl-top-right {
width: 19%;
display: inline-block;
}
.u-left {
border-radius: 3px;
}
.up-head {
font-size: 18px;
color: #2b2b2b;
font-weight: 500;
}
.container-ck {
background-color: #ffffff;
width: 768px;
min-width: 37.5em;
padding: 3.12em 1.87em;
/* position: absolute; */
/* transform: translateX(-50%); */
left: 50%;
top: 1em;
box-shadow: 0 1.25em 3.43em rgba(0, 0, 0, 0.08);
border-radius: 0.5em;
margin: auto;
margin-top: 65px;
}
.ck-btn {
padding-top: 6px;
}
input[type="file"] {
display: none;
}
label {
display: block;
position: relative;
background-color: #025bee;
color: #ffffff;
font-size: 1.1em;
text-align: center;
width: 11em;
padding: 1em 0;
border-radius: 0.3em;
margin: 0 auto 1em auto;
cursor: pointer;
}
#image-display {
position: relative;
width: 98%;
margin: 0 auto;
display: flex;
justify-content: space-evenly;
gap: 21px;
flex-wrap: wrap;
}
#image-display figure {
width: 48%;
}
#image-display img {
width: auto;
height: auto;
}
#image-display figcaption {
font-size: 0.8em;
text-align: center;
color: #5a5861;
}
#error {
text-align: center;
color: #ff9191;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
left: 50%;
top: 50%;
-ms-transform: translate(-50%,-50%);
-moz-transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
background: #ffffffa8;
z-index: 9999;
backdrop-filter: blur(3px);
cursor: default;
}
.container22 {
max-width: 440px;
background: #fff;
border-radius: 8px;
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
margin: auto;
max-width: 780px;
padding: 17px;
margin-top: 20px;
}
.overflow-x-hidden {
overflow:visible;
width: 640px;
margin: auto;
margin-top: 90px;
}
.i-right {
height: 29px !important;
}
.dd-t {
font-size: 14px;
}
.t2-line {
line-height: 19px;
}
html {
font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;
line-height:1.5
}
.container22{
max-width: 594px;
}
.drag-area {
min-height: 285px;
border: 2px dashed #e0eafc;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
background: #fafafa;
display: flex;
flex-direction: column;
align-items: center;
padding: 17px;
border-width: 2px;
border-radius: 8px;
border-color: #656fd0;
border-style: dashed;
background-color: rgb(250, 250, 250);
color: rgb(189, 189, 189);
outline: none;
cursor: pointer;
position: relative;
}
h3 {
margin-bottom: 20px;
font-weight: 500;
}
.drag-area .icon {
font-size: 50px;
color: #1683ff;
}
.InlineSVG {
display: inline;
}
.flex {
display: flex;
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
}
.drag-area .button {
padding-top: 5px;
padding-bottom: 0px;
}
input {
height: 34px;
border: 1px solid #d2d4de;
padding-left: 13px;
border-radius: 4px;
font-size: 14px;
}
.justify-center {
justify-content: center;
}
.drag-area .header {
font-size: 20px;
font-weight: 500;
color: #34495e;
}
.drag-area .support {
font-size: 13px;
color: #a3a3a3;
margin: 10px 0 15px 0;
font-weight: 300;
}
.top-out {
width: 100%;
border-bottom: 1px solid #e2e2e2;
margin-bottom: 18px;
}
.icon-outer1 {
justify-content: center;
margin-bottom: 4px;
}
#sub2 {
margin-left: 2px;
}
#submit {
margin-top: -1px;
text-align: center;
}
.drag-area .button {
font-size: 13px;
font-weight: 400 !important;;
color: #fafafa;
cursor: pointer;
background: #656fd0 !important;
border-radius: 5px;
margin-top: 20px;
margin-bottom: 7px;
min-height: 33px;
}
.hideit {
display: none !important;
}
.dropped {
padding: 0;
margin: 0;
border: none;
background: transparent;
}
.drag-area.active {
border-color: #656fd0;
border-style: solid;
opacity: 1;
}
.drag-area img {
width: 100%;
height: 100%;
object-fit: cover;
}
.download {
background-color:#4CAF50;
border: none;
color: white;
padding: 6px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 3px 1px;
border-radius: 12px;
cursor: pointer;
width: 100%;
}
.uploader-svg {
height: 26px !important;
opacity: .2;
width: auto !important;
margin: 9px;
}
<body>
<div class="container22">
<div class="drag-area">
<div id="error" class="hideit"></div>
<div id="image-display"></div>
<div id="submit">
<div class="flex icon-outer1"><svg class="icon faded uploader-svg" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 91.27"><defs><style>.cls-1{fill-rule:evenodd;}</style></defs><title>picture</title><path class="cls-1" d="M87.29,16.88A11.35,11.35,0,1,1,75.94,28.23,11.35,11.35,0,0,1,87.29,16.88Zm27.33,74.39H8.26a8.27,8.27,0,0,1-5.83-2.44h0A8.24,8.24,0,0,1,0,83V8.26A8.26,8.26,0,0,1,2.42,2.42h0A8.26,8.26,0,0,1,8.26,0H114.62a8.26,8.26,0,0,1,5.83,2.43h0a8.26,8.26,0,0,1,2.42,5.84V83a8.24,8.24,0,0,1-2.42,5.83h0a8.27,8.27,0,0,1-5.83,2.44Zm-7.35-9.43L87.6,50.46a4.52,4.52,0,0,0-7.65,0L70.66,65.39,80.77,81.84H76.62l-27.57-44c-2.54-3.39-6.61-3.13-8.88,0l-27,44H9.42V9.42h104V81.84Z"/></svg><div class="ms-2 me-2" style="height: 44px; border-left: 1px solid rgb(203, 203, 203);"></div><svg class="icon faded uploader-svg i-right" id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 98.27"><title>photos</title><path d="M4.84,27.31H90.76a4.77,4.77,0,0,1,3.4,1.41,4.84,4.84,0,0,1,1.41,3.4V93.47a4.75,4.75,0,0,1-1.41,3.39,1.36,1.36,0,0,1-.25.22,4.67,4.67,0,0,1-3.18,1.19H4.81A4.81,4.81,0,0,1,0,93.47V32.12a4.77,4.77,0,0,1,1.41-3.4,4.83,4.83,0,0,1,3.4-1.41ZM32.15,0h85.92a4.77,4.77,0,0,1,3.4,1.41,4.84,4.84,0,0,1,1.41,3.4V66.16a4.75,4.75,0,0,1-1.41,3.39,1.09,1.09,0,0,1-.25.22A4.67,4.67,0,0,1,118,71h-5.38V65.22h4.51V5.71H33.06v4.2H27.31V4.81a4.77,4.77,0,0,1,1.41-3.4A4.84,4.84,0,0,1,32.12,0ZM18.5,13.66h85.92a4.75,4.75,0,0,1,3.39,1.41,4.8,4.8,0,0,1,1.41,3.39V79.81a4.77,4.77,0,0,1-1.41,3.4,1.4,1.4,0,0,1-.25.22,4.67,4.67,0,0,1-3.18,1.19H99V78.88h4.51V19.37H19.4v4.2H13.65V18.46a4.81,4.81,0,0,1,4.81-4.8ZM24.68,44a6.9,6.9,0,1,1-6.89,6.89A6.89,6.89,0,0,1,24.68,44Zm29,29.59L67.49,49.71,82.14,86.77H13.77V82.18l5.74-.29,5.75-14.08,2.87,10.06h8.62l7.47-19.25L53.7,73.56ZM89.86,33H5.75V92.53H89.86V33Z"/></svg></div>
<div class="2-line-top t2-line"><span class="dd-t">Drag & drop <u>or</u> </span> </div> <div class="2-line-bottom t2-line"> <span class="dd-t">browse for photo(s)</span> </div><input type="file" id="upload-button" multiple accept="image/*" />
<label class="ck-btn flex self-end justify-center px-4 py-2 mt-5 text-sm font-medium text-white transition duration-150 ease-in-out border border-transparent rounded-md bg-wave-600 hover:bg-wave-500 focus:outline-none focus:border-wave-700 focus:shadow-outline-wave active:bg-wave-700 button" for="upload-button"><i class="fa-solid fa-upload"></i>Browse files
</label>
<div id="sub2"><span class="support">Supports: JPEG, JPG</span></div>
</div>
</div>
</div>
</body>