js - How to Make a img from a dataTransfer img
up vote
0
down vote
favorite
I have a img <img id="img1">
and a div <div class="imgdrop" id="imgdropdiv" ondragover="event.preventDefault();" ondrop="dropimg(event)">
How can I set the img tag's img to imgdata.result with this js code
imgdrop = document.getElementById("imgdrop");
img = document.getElementById("img1");
function dropimg(file) {
file.preventDefault();
if (file.dataTransfer.items) {
if (file.dataTransfer.items[0].kind === 'file') {
var files = file.dataTransfer.files||e.target.files;
var type = files[0].type;
if (type == "image") {
var imgdata = new FileReader();
imgdata.readAsDataURL(files[0]);
img.src = imgdata.result;
console.log(imgdata.result);
} else { (alert('File is not image' + file.type));}
}
} else {imgdrop.val = file.dataTransfer.file;}
};
how can I do this? Any help would really be appreciated.
javascript html image
add a comment |
up vote
0
down vote
favorite
I have a img <img id="img1">
and a div <div class="imgdrop" id="imgdropdiv" ondragover="event.preventDefault();" ondrop="dropimg(event)">
How can I set the img tag's img to imgdata.result with this js code
imgdrop = document.getElementById("imgdrop");
img = document.getElementById("img1");
function dropimg(file) {
file.preventDefault();
if (file.dataTransfer.items) {
if (file.dataTransfer.items[0].kind === 'file') {
var files = file.dataTransfer.files||e.target.files;
var type = files[0].type;
if (type == "image") {
var imgdata = new FileReader();
imgdata.readAsDataURL(files[0]);
img.src = imgdata.result;
console.log(imgdata.result);
} else { (alert('File is not image' + file.type));}
}
} else {imgdrop.val = file.dataTransfer.file;}
};
how can I do this? Any help would really be appreciated.
javascript html image
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a img <img id="img1">
and a div <div class="imgdrop" id="imgdropdiv" ondragover="event.preventDefault();" ondrop="dropimg(event)">
How can I set the img tag's img to imgdata.result with this js code
imgdrop = document.getElementById("imgdrop");
img = document.getElementById("img1");
function dropimg(file) {
file.preventDefault();
if (file.dataTransfer.items) {
if (file.dataTransfer.items[0].kind === 'file') {
var files = file.dataTransfer.files||e.target.files;
var type = files[0].type;
if (type == "image") {
var imgdata = new FileReader();
imgdata.readAsDataURL(files[0]);
img.src = imgdata.result;
console.log(imgdata.result);
} else { (alert('File is not image' + file.type));}
}
} else {imgdrop.val = file.dataTransfer.file;}
};
how can I do this? Any help would really be appreciated.
javascript html image
I have a img <img id="img1">
and a div <div class="imgdrop" id="imgdropdiv" ondragover="event.preventDefault();" ondrop="dropimg(event)">
How can I set the img tag's img to imgdata.result with this js code
imgdrop = document.getElementById("imgdrop");
img = document.getElementById("img1");
function dropimg(file) {
file.preventDefault();
if (file.dataTransfer.items) {
if (file.dataTransfer.items[0].kind === 'file') {
var files = file.dataTransfer.files||e.target.files;
var type = files[0].type;
if (type == "image") {
var imgdata = new FileReader();
imgdata.readAsDataURL(files[0]);
img.src = imgdata.result;
console.log(imgdata.result);
} else { (alert('File is not image' + file.type));}
}
} else {imgdrop.val = file.dataTransfer.file;}
};
how can I do this? Any help would really be appreciated.
javascript html image
javascript html image
asked Nov 10 at 16:01
Stemboy4002
64
64
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240747%2fjs-how-to-make-a-img-from-a-datatransfer-img%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password