Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (94 sloc) 2.59 KB
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Scoped CSS Variables and JS</title>
<script src=""></script>
<div id="app">
<h2>Update CSS Variables with <span class='hl'>JS</span></h2>
<div class="controls">
<label for="spacing">Spacing:</label>
<input id="spacing" type="range" min="10" max="200" v-model="spacing">
<label for="blur">Blur:</label>
<input id="blur" type="range" min="0" max="25" v-model="blur">
<label for="base">Base Color</label>
<input id="base" type="color" v-model="base">
<img src="">
var app = new Vue({
el: '#app',
data: {
spacing: 10,
blur: 10,
base: "#ffc600"
mounted: function() {
// Update the CSS Variables when mounted
methods: {
// Update the style of the root DOM element that the Vue instance is managing
updateCSSVariable: function(name, value) {
this.$, value)
updateCSSSpacing: function () {
this.updateCSSVariable('--spacing', `${this.spacing}px`)
updateCSSBlur: function () {
this.updateCSSVariable('--blur', `${this.blur}px`)
updateCSSBase: function () {
this.updateCSSVariable('--base', this.base)
watch: {
// When the value of the spacing attribute changes, update its CSS variable
spacing: function(newValue, oldValue) {
// When the value of the blur attribute changes, update its CSS variable
blur: function(newValue, oldValue) {
// When the value of the base attribute changes, update its CSS variable
base: function(newValue, oldValue) {
img {
padding: var(--spacing);
background: var(--base);
filter: blur(var(--blur));
.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 {