-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg.js
37 lines (28 loc) · 999 Bytes
/
img.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
let upload = document.querySelector("#upload")
let photoUpload = document.querySelector("#photo-upload")
let download = document.querySelector("#download")
download.addEventListener("click", ()=>{
let filePath = canvas.toDataURL("image/jpg")
let aTag = document.createElement('a')
aTag.setAttribute('download', 'canvas.jpg')
aTag.setAttribute('href', filePath);
aTag.click();
aTag.remove();
})
upload.addEventListener('click', function(){
photoUpload.click()
})
photoUpload.addEventListener('change', function(){
let fileObject = photoUpload.files[0];
// gives you an image url
let filePath = URL.createObjectURL(fileObject);
// image tag created
let img = document.createElement("img")
img.setAttribute("src", filePath)
img.setAttribute("id","image-id")
// console.log(img);
// append image to documnet -> body
// document.body.appendChild(img)
let stickyContent = createSticky()
stickyContent.appendChild(img)
})