Update CSS Variables with JS

Developer
Size
2,335 Kb
Views
10,120

How do I make an update css variables with js?

What is a update css variables with js? How do you make a update css variables with js? This script and codes were developed by Wes Bos on 09 December 2022, Friday.

Update CSS Variables with JS Previews

Update CSS Variables with JS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Update CSS Variables with JS</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<div class="controls"> <label>Spacing:</label> <input type="range" id="spacing" min="10" max="200" value="10"> <label>Blur:</label> <input type="range" id="blur" min="0" max="25" value="10"> <label>Base Color</label> <input type="color" id="base" value="#ffc600">
</div>
<img src="http://unsplash.it/800/500?image=899">
<p class="love">Made by <a href="https://twitter.com/wesbos">@wesbos</a> 

Update CSS Variables with JS - Script Codes CSS Codes

:root { --base: #ffc600; --spacing: 10px; --blur: 10px;
}
body { text-align: center;
}
img { padding: var(--spacing); background: var(--base); -webkit-filter: blur(var(--blur)); /* 

Update CSS Variables with JS - Script Codes JS Codes

 // get the inputs const inputs = [].slice.call(document.querySelectorAll('.controls input')); // listen for changes inputs.forEach(input => input.addEventListener('change', handleUpdate)); inputs.forEach(input => input.addEventListener('mousemove', handleUpdate)); function handleUpdate(e) { // append 'px' to the end of spacing and blur variables const suffix = (this.id === 'base' ? '' : 'px'); document.documentElement.style.setProperty(`--${this.id}`, this.value + suffix); }
Update CSS Variables with JS - Script Codes
Update CSS Variables with JS - Script Codes
Home Page Home
Developer Wes Bos
Username wesbos
Uploaded December 09, 2022
Rating 4.5
Size 2,335 Kb
Views 10,120
Do you need developer help for Update CSS Variables with JS?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Wes Bos (wesbos) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!