javascript - Is there a way to change a <span> background image with an input files temporary image? -
i have span has default background image fills face of . once file selected change background of span chosen image. possible?
i have html:
<div class="one"> <span class="two upload_image"></span> <input id="input_file" class="three" type="file" name="e_picture" accept="image/*"> </div>
my current js (changes src of upload_image class) selected image, not chosen image:
function readurl(input) { if (input.files && input.files[0]) { var reader = new filereader(); reader.onload = function (e) { $('.upload_image').css('background-image', 'url("http://www.thechefsdirectory.com/x/x_images/x_template/form/upload_document.png")'); } reader.readasdataurl(input.files[0]); } } $("#input_file").change(function(){ readurl(this); });
this input looks like:
the perfect scenario. user clicks input , selects file upload.
the background changes default css background temporary preview.
then if user clicks file again, can change image.
can offer solution?
yes, using file api.
in nutshell, file api allows javascript in browser access local file system. allow load image , display (the examples list use case).
Comments
Post a Comment