Предварительный просмотр изображения с помощью JS
HTML:
CSS:
JS:
👉 @FrontendPortal | #js
HTML:
<img src="img/unknow.png">
<input type="file">
CSS:
img {
height: 150px;
width: 150px;
border-radius: 50%;
object-fit: cover;
background-color: #dfdfdf;
}
JS:
const image = document.querySelector("img"),
input = document.querySelector("input");
input.addEventListener("change", () => {
image.src = URL.createObjectURL(input.files[0]);
});
👉 @FrontendPortal | #js