Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions JS-Day/Playing with Variables/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Scoped CSS Variables and JS</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>

<div class="controls">
<label for="spacing">Spacing:</label>
<input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">

<label for="blur">Blur:</label>
<input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">

<label for="base">Base Color</label>
<input id="base" type="color" name="base" value="#ffc600">
</div>

<img src="https://source.unsplash.com/7bwQXzbF6KE/800x500" alt="nice">
</body>
<script src="script.js"></script>
</html>
22 changes: 22 additions & 0 deletions JS-Day/Playing with Variables/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@



//select all inputs which are in .controls class
const inputs = document.querySelectorAll('.controls input');

function handleUpdate() {
//dataset will push everything that has data 'dash' (data-xxx) on
//that element and put into object for you.
//if we don't put the fallback '', when we reach the attribute
//that has no data-sizing, we will push undefined!
const suffix = this.dataset.sizing || '';
// console.log(suffix);
// this line will print HTML name attribute for that specific element
// console.log(this.name)
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix)


}

inputs.forEach((input) => input.addEventListener('change', handleUpdate));
inputs.forEach((input) => input.addEventListener('mousemove', handleUpdate));
38 changes: 38 additions & 0 deletions JS-Day/Playing with Variables/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:root {
--base: #ffc600;
--spacing: 10px;
--blur: 10px;
}

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

/*Now, changing color for the JS span*/
.hl {
color: var(--base);
}


/*
misc styles, nothing to do with CSS variables
*/

body {
text-align: center;
background: #193549;
color: white;
font-family: 'helvetica neue', sans-serif;
font-weight: 100;
font-size: 50px;
}

.controls {
margin-bottom: 50px;
}

input {
width: 100px;
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
[2. ModalBox 💬](https://github.com/cheatsheet1999/FrontEndCollection/issues/23)
[3. Drum Kit 🥁](https://github.com/cheatsheet1999/FrontEndCollection/tree/main/JS-Day/DrumKit)
[4. Mini Clock 🕑](https://github.com/cheatsheet1999/FrontEndCollection/tree/main/JS-Day/Mini%20Clock)
[5. Playing with Variables 🎩](https://github.com/siyuan25/FrontEndCollection/tree/main/JS-Day/Playing%20with%20Variables)

## Deep Dive in Javascript
[_Learn More on BFE.dev_](https://bigfrontend.dev/)
Expand Down