Created
January 7, 2022 19:14
-
-
Save manuelcanga/c615def89c2333b5ed924e5ca66bb5c3 to your computer and use it in GitHub Desktop.
Subida de imágenes con previo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type='file' onchange="previewImage(this, 'preview-image');" /> | |
<img id="preview-image" src="http://placehold.it/300" alt="image preview" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function previewImage(input, container) { | |
if( input.files.length < 1) { | |
return ; | |
} | |
var reader = new FileReader(); | |
reader.onload = function (e) { | |
document.getElementById(container).src = e.target.result; | |
}; | |
reader.readAsDataURL(input.files[0]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
img#preview-image{ | |
max-width:300px; | |
} | |
input[type=file]{ | |
padding:10px; | |
background:#2d2d2d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment