Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions 03 - CSS Variables/index-FINISHED.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>

body {
text-align: center;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@encryptid this seems like a weird change, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah, somebody went a little crazy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has body defined twice. Can you consolidate this into one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, haha. Right. Pushed changes.

body {
background: #193549;
color: white;
font-family: 'helvetica neue', sans-serif;
Expand All @@ -60,6 +63,11 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
</style>

<script>
// First step: query all inputs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments still here! 😝

// Step two: iterate over inputs, add 'change' and 'mousemove' event handlers
// Step three: define that event handler
// b.) have event handler update CSS variable

const inputs = document.querySelectorAll('.controls input');

function handleUpdate() {
Expand Down
37 changes: 35 additions & 2 deletions 03 - CSS Variables/index-START.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<title>Scoped CSS Variables and JS</title>
</head>

<body>
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>

Expand All @@ -21,13 +24,26 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">

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

img {
padding: var(--spacing);
filter: blur(var(--blur));
background-color: var(--base);
}
/*
misc styles, nothing to do with CSS variables
*/

body {
text-align: center;
}

body {
background: #193549;
color: white;
font-family: 'helvetica neue', sans-serif;
Expand All @@ -40,12 +56,29 @@ <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
}

input {
width:100px;
width: 100px;
}
</style>

<script>
// First step: query all inputs.
// Step two: iterate over inputs, add 'change' and 'mousemove' event handlers
// Step three: define that event handler
// b.) have event handler update CSS variable

const inputs = document.querySelectorAll(".controls input");

function handleUpdate() {
//console.log(this);
const suffix = this.dataset.sizing || "";
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}

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

</script>

</body>
</html>

</html>