CSS3可调节并实时预览的阴影效果

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>CSS3可调节并实时预览的阴影效果</title>
  
  
<style>
    .slider {
  -webkit-appearance: none;
  max-width: 350px;
  width: 100%;
  height: 10px;
  border-radius: 5px;   
  background: #1B2B33;
  outline: none;
  margin-top: 50px;
  margin-bottom: 30px
}

.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{
  background: #EEF2F6;
  border: none;
  padding: 0 20px;
  font-size: 15px;
  color: #1B2B33;
  font-family: sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.container{
  width: 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{
  max-width: 400px;
  width: 100%;
  height: 200px;
  min-height: 200px;
  background: white;
  border-radius: 9px;
  margin-top: 15px;
  box-shadow : 0 1px 2px rgba(0, 0, 0, 0.50), 0 1px 3px rgba(0, 0, 0, 0.46);
}

</style>

  
</head>

<body>

  <div class="container">
  
  <div id="info">
    <h1>CSS3可调节并实时预览的阴影效果</h1>
  </div>
  
  <div id="box"><img src="http://blog.img.duanshuilu.com/20210630115943.png" alt="demo" /></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>

<script>
    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;
  
}
</script>


</body>

</html>


CSS3可调节并实时预览的阴影效果

评论者:[[ schemeInfo.user.username ]]

评论内容:[[ schemeInfo.pbody ]]

评论时间:[[ schemeInfo.ptime ]]





发表你的评论:

提交评论
上一篇:
下一篇: