X Tutup
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions 03 - CSS Variables/index-START.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">

<style>
:root {
--base: #ffc600;
--spacing: 10px;
--blur: 10px;
}

img {
padding: var(--spacing);
background: var(--base);
filter: blur(var(--blur));
}

.h1 {
color: var(--base);
}

/*
misc styles, nothing to do with CSS variables
Expand All @@ -44,8 +59,7 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
}
</style>

<script>
</script>
<script src="script.js"></script>

</body>
</html>
11 changes: 11 additions & 0 deletions 03 - CSS Variables/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const inputs = document.querySelectorAll('.controls input');

const handleUpdate = (e) => {
const suffix = e.target.dataset.sizing || '';
const name = e.target.name;
const value = e.target.value;
document.documentElement.style.setProperty(`--${name}`, value + suffix);
};

inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
X Tutup