Drag and Drop File Preview

Developer
Size
3,444 Kb
Views
22,264

How do I make an drag and drop file preview?

Drag an image to the plus button (file input), watch it just be there.. What is a drag and drop file preview? How do you make a drag and drop file preview? This script and codes were developed by Adam Grayson on 10 November 2022, Thursday.

Drag and Drop File Preview Previews

Drag and Drop File Preview - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Drag and Drop File Preview</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container"> <div class="header"> <h1>Drag &amp; drop image file to the plus button, or click to upload.</h1> </div> <div class="content"> <div class="file-input"> <p>+</p> <input class="image-upload" type="file" accept="image/*;capture=camera"/> </div><img class="image-preview" src="#"/> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Drag and Drop File Preview - Script Codes CSS Codes

* { box-sizing: border-box;
}
html, body { font-family: "TrebuchetMS", trebuchet, sans-serif; background-color: #EEEEEF;
}
.container h1 { text-align: center; font-size: 24px; color: #FFFFFF;
}
.header { padding: 50px 0 80px; background-color: #00BCD4;
}
.content { width: 576px; min-height: 64px; background-color: #FFFFFF; margin: -32px auto 0; padding: 5px; position: relative; box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.14);
}
.file-input { position: absolute; top: 0; right: -80px; z-index: 0; width: 64px; height: 64px; background-color: #EEFF41; border-radius: 50%; text-align: center; line-height: 61px; font-size: 50px; color: #000000; box-shadow: 0px 8px 12px 0px rgba(0, 0, 0, 0.14);
}
.file-input input { position: absolute; top: 0; left: 0; z-index: 1; width: 100%; height: 100%; opacity: 0; cursor: pointer;
}
.image-preview { max-width: 100%; display: block;
}

Drag and Drop File Preview - Script Codes JS Codes

(function() { var readFilePath; readFilePath = function(input) { var fileReader; if (input.files && input.files[0]) { fileReader = new FileReader(); fileReader.onload = function(e) { return $('.image-preview').attr('src', e.target.result); }; return fileReader.readAsDataURL(input.files[0]); } }; $('.image-upload').change(function() { return readFilePath(this); });
}).call(this);
Drag and Drop File Preview - Script Codes
Drag and Drop File Preview - Script Codes
Home Page Home
Developer Adam Grayson
Username agrayson
Uploaded November 10, 2022
Rating 3
Size 3,444 Kb
Views 22,264
Do you need developer help for Drag and Drop File Preview?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Adam Grayson (agrayson) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!