-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8c90d7
commit a903481
Showing
3 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const FILE_TYPES = ['gif', 'jpg', 'jpeg', 'png']; | ||
|
||
const avatarElement = document.querySelector('.img-upload__preview img'); | ||
const avatarPreviews = document.querySelectorAll('.effects__preview'); | ||
const uploadFileInputElement = document.querySelector('#upload-file'); | ||
|
||
uploadFileInputElement.addEventListener('change', () => { | ||
const file = uploadFileInputElement.files[0]; | ||
//получаем имя файла через name и приводим к одному виду | ||
const fileName = file.name.toLowerCase(); | ||
//Делаем проверку совпадает ли имя нашего файла с допустимыми | ||
const matches = FILE_TYPES.some((item) => fileName.endsWith(item)); | ||
|
||
if(matches) { | ||
avatarElement.src = URL.createObjectURL(file); | ||
avatarPreviews.forEach((el) => el.style.setProperty('background-image', `url(${URL.createObjectURL(file)})`)); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters