Skip to content

Instantly share code, notes, and snippets.

@scottyzen
Created December 25, 2018 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottyzen/ebf6d0f8445016f45f2a60fb480c502d to your computer and use it in GitHub Desktop.
Save scottyzen/ebf6d0f8445016f45f2a60fb480c502d to your computer and use it in GitHub Desktop.
Cast shadow visualization
<div class="container">
<div id="info">
<h1>Cast shadow visualization</h1>
</div>
<div id="box"></div>
<div class="slidecontainer">
<input type="range" min="1" max="100" value="1" class="slider" id="myRange">
<p>box-shadow <span style="color: #fff">:</span> <span id="shadow-info">0 1px 2px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.46)</span><span style="color: #fff"> ;</span></p>
</div>
</div>
var slider = document.getElementById("myRange");
var box = document.getElementById("box");
var shadowInfo = document.getElementById("shadow-info");
slider.oninput = function() {
var v = this.value;
var largeShadow = `0 ${(v/3).toFixed(0)}px ${v}px rgba(0, 0, 0, ${(.5 - (v/ 500)).toFixed(2)})`;
var smallShadow = `0 ${(v/1.5).toFixed(0)}px ${(v*1.5).toFixed(0)}px rgba(0, 0, 0, ${(.5 - (v/ 50)).toFixed(2)})`;
var shadow = largeShadow + ", " + smallShadow;
if( (.5 - (v/ 50)).toFixed(2) <= 0 ){
shadow = largeShadow;
}
box.style.boxShadow = shadow;
shadowInfo.innerText = shadow;
}
.slider {
-webkit-appearance: none;
width: 250px;
height: 10px;
border-radius: 5px;
background: #1B2B33;
border-bottom: 1px solid #ddd;
outline: none;
opacity: 0.9;
-webkit-transition: .2s;
transition: opacity .2s;
margin-top: 75px;
margin-bottom: 50px
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 1px rgba(0,0,0,.5);
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 3px rgba(0,0,0,.1);
cursor: pointer;
}
body{
padding: 0;
marging: 0;
background: #F1F5F8;
border: none;
font-size: 15px;
color: #1B2B33;
font-family: sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.container{
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.slidecontainer{
max-width: 600px;
width: 100%;
text-align: center;
}
.slidecontainer p{
font-weight: bold;
padding: 8% 3%;
background: #1B2B33;
border-radius: 6px;
color: #EB6069;
}
.slidecontainer p span {
color: #E9B684
}
#info{
max-width: 500px;
text-align: center;
}
#box{
width: 400px;
height: 200px;
min-height: 200px;
background: white;
border-radius: 9px;
margin-top: 20px;
box-shadow : 0 1px 2px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.46);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment