Reputation: 1
I have a problem. I need to create one feature for site. User can select image on his computer and that image have to be installed as background-image in body. But I have two problems:
What can I do to solve it?
Upvotes: 0
Views: 79
Reputation: 207
HTML:
<input type='file'/>
<img id="someImage" src="#"/>
Javascript:
$(function(){
$(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = onImageLoaded;
reader.readAsDataURL(this.files[0]);
}
});
})
function onImageLoaded(e){
$('#someImage').attr('src', e.target.result)
}
Upvotes: 1