-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewpage.js
27 lines (26 loc) · 915 Bytes
/
newpage.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
const blogTitleField=document.querySelector('.title');
const articleFeild=document.querySelector('.article');
//banner
const bannerTmage=document.querySelector('#banner-upload');
const banner=document.querySelector(".banner");
let bannerPath;
const publishBtn=document.querySelector('.publish-btn');
const uploadInput=document.querySelector('#image-upload');
bannerImage.addEventListener('change',()=>{
uploadImage(bannerImage,"banner");
});
const uploadImage=(uploadFile,uploadType)=>{
const[file]=uploadFile.files;
if(file && file.type.include("image")){
const formdata=new FormData();
formdata.append('image',file);
fetch('/uploads',{
method:'post',
body:formdata
}).then(res=>res.json())
.then(data=>{
bannerPath=`${location.origin}/${data}`;
banner.style.backgroundImage=`url("${bannerPath}")`;
})
}
}