Skip to content

Commit

Permalink
Update dynamic styles
Browse files Browse the repository at this point in the history
  • Loading branch information
agatemosu committed Jul 22, 2024
1 parent 7adfb47 commit 7cdcbf6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 1 addition & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,7 @@
<div id="buttons-container">
<button type="button" onclick="addRow()">New tier</button>
<button type="button" onclick="selectImages()">Select images</button>
<input
type="checkbox"
id="square-img"
onchange="dynamicStyle(this, '.image { height: 80px; width: 80px; }')"
/>
<input type="checkbox" id="square-img" onchange="dynamicStyle(this)" />
<label for="square-img">Square images</label>
</div>

Expand Down
8 changes: 5 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ function initializeDragula() {
});
}

function dynamicStyle(checkbox, css) {
function dynamicStyle(checkbox) {
const importText = `@import "./styles/${checkbox.id}.css";`;

if (checkbox.checked) {
dynamicStyles.innerHTML += css;
dynamicStyles.innerHTML += importText;
} else {
dynamicStyles.innerHTML = dynamicStyles.innerHTML.replace(css, "");
dynamicStyles.innerHTML = dynamicStyles.innerHTML.replace(importText, "");
}
}
4 changes: 4 additions & 0 deletions styles/square-img.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.image {
width: 80px;
height: 80px;
}

0 comments on commit 7cdcbf6

Please sign in to comment.