Skip to content

Commit

Permalink
Merge pull request #1 from enumbutz/enumbutz-patch-1
Browse files Browse the repository at this point in the history
Change css variables with js
  • Loading branch information
enumbutz authored Oct 25, 2017
2 parents da859d3 + 3135372 commit f4304bd
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions change-css-with-js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<title>Updata CSS variables with JS </title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<h2>Updata CSS variables with <span class="hl">JS</span> </h2>
<div class="control">
<label>Spacing:</label>
<input type="range" name="spacing" min="10" max="20" data-sizing='px'>
<label>Blur:</label>
<input type="range" name="blur" min="0" max='20' data-sizing='px'>
<label>Color:</label>
<input type="color" name="color" value="#ffc600">
<br>
<br>
</div>
<img class='b' src="https://az616578.vo.msecnd.net/files/2016/11/06/636140659029117301-893379077_city.jpeg" width="60%" height="60%">
<img class='a' src="https://az616578.vo.msecnd.net/files/2016/11/06/636140659029117301-893379077_city.jpeg" width="10%" height="10%">
</body>

<style type="text/css">
:root {
--spacing:10px;
--color:#ffc600;
--blur:10px;
}
.b {
padding: var(--spacing);
filter: blur(var(--blur));
background: var(--color);
}
.hl{
color:var(--color) ;
}

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


</style>
<script type="text/javascript">
var inputs = document.querySelectorAll('.control input');

function handleUpdate(){
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>
</html>

0 comments on commit f4304bd

Please sign in to comment.