Skip to content

Commit

Permalink
Use <div> for images
Browse files Browse the repository at this point in the history
  • Loading branch information
agatemosu committed Jul 22, 2024
1 parent 7cdcbf6 commit 1d05ef7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
13 changes: 10 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,18 @@ function selectImages() {

function uploadImages(files) {
for (const file of files) {
const image = document.createElement("img");
const image = new Image();
image.src = URL.createObjectURL(file);
image.className = "image";

imagesBar.appendChild(image);
const imageEl = document.createElement("div");
imageEl.classList.add("image");
imagesBar.appendChild(imageEl);

image.onload = () => {
imageEl.style.aspectRatio = `${image.width} / ${image.height}`;
imageEl.style.backgroundImage = `url("${image.src}")`;
imageEl.style.minHeight = `${Math.min(image.height, 80)}px`;
};
}

initializeDragula();
Expand Down
20 changes: 13 additions & 7 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ body {

.tier-label {
position: relative;
min-height: 85px;
min-height: 80px;
width: 100px;
display: flex;
align-items: center;
Expand Down Expand Up @@ -92,6 +92,12 @@ p {
text-align: center;
}

.sort {
display: flex;
flex-flow: row wrap;
gap: 2px;
}

.tier {
flex-grow: 1;
background-color: var(--tier-bg);
Expand Down Expand Up @@ -130,6 +136,7 @@ p {

.option img {
transition: ease 100ms;
cursor: pointer;
}

.option img:hover {
Expand Down Expand Up @@ -184,14 +191,13 @@ label::before {
margin-right: 5px;
}

img {
cursor: pointer;
}

.image {
display: inline-flex;
vertical-align: top;
cursor: pointer;
background-size: contain;
background-repeat: no-repeat;
max-height: 80px;
margin-left: 2px;
object-fit: cover;
}

#images-bar {
Expand Down
2 changes: 2 additions & 0 deletions styles/square-img.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.image {
background-position: center;
background-size: cover;
width: 80px;
height: 80px;
}

0 comments on commit 1d05ef7

Please sign in to comment.