Untitled
unknown
plain_text
3 years ago
1.0 kB
37
Indexable
function imagesPreview(input, placeToInsertImagePreview) {
return new Promise((resolve, reject) => {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$($.parseHTML('<img class="preview__thumb">')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
if (i === filesAmount - 1) {
resolve(); // resolve the promise when all images have been added
}
};
reader.readAsDataURL(input.files[i]);
}
} else {
reject(new Error('No files provided'));
}
});
}
$('#file__input').on('change', function() {
imagesPreview(this, '#the__gallery')
.then(() => {
var count = $('.preview__thumb').length;
console.log('Count:', count);
// You can apply your custom styles based on the count here
})
.catch((error) => {
console.error(error);
});
});
Editor is loading...