js+svg实现背景色从明亮到暗色调节滑块拖动效果代码

代码语言:html

所属分类:拖放

代码描述:js+svg实现背景色从明亮到暗色调节滑块滑块拖动效果代码带灯光穿越动画效果代码,可点击可拖动。

代码标签: js svg 背景色 明亮 暗色 调节 滑块 拖动

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

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

<head>
  <meta charset="UTF-8">
  

  
<style>
* {
  box-sizing: border-box;
}
html {
  height: -webkit-fill-available;
}
body {
  --angle: 270deg;
  --hue1: 40;
  --hue2: 189;
  --hue3: 330;
  --hue4: 270;
  --light: 50%;
  --l: 0.40;
  --r1: oklch(var(--l) 0.1 60 / 0.75);

  background-image:
    linear-gradient(var(--angle), hsl(var(--hue1), 100%, var(--light)), hsl(var(--hue2), 100%, var(--light)));
  font-family: 'Montserrat', sans-serif;
  margin: 0;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  padding: 1ch;
}
body:before {
  content: "";
  position: fixed;
  inset: 0;
  -webkit-mask-image: linear-gradient(to bottom, transparent, black);
          mask-image: linear-gradient(to bottom, transparent, black);
  background: linear-gradient(var(--angle), hsl(var(--hue3), 100%, calc(var(--light) + 20%)), hsl(var(--hue4), 50%, calc(var(--light) - 10%)));	
}

.daynight {
  background-color: hsla(0, 0%, 0%, 0.15);
  border: 2px solid var(--r1);
  border-radius: 3em;
  color: hsla(0, 0%, 100%, 0.8);
  display: grid;
  padding: .75em;
  position: relative;
  width: 100%;
}
.daynight-icons {
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  position: relative;
  z-index: 1;
}
.daynight-icons svg {
  fill: none;
  height: 2em;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.25;
  stroke: currentColor;
  width: 2em;
}
.daynight-input {
  appearance: none;
  background: transparent;
  inset: 0;
  position: absolute;
}
.daynight-input::-webkit-slider-runnable-track {
  height: 100%;
  width: 100%;
}
.daynight-input::-webkit-slider-thumb {
  appearance: none;
  aspect-ratio: 1 / 1;
  background: var(--r1);
  border-radius: 100%;
  height: 100%;
}

/* -moz-stuff */
@-moz-document url-prefix() { 
  .daynight-input {
     height: 100%;
     width: 100%;
  }
}
.daynight-input::-moz-range-track {
  border-radius: 3em;
  height: 100%;
  width: 100%;
}
.daynight-input::-moz-range-thumb {
  appearance: none;
  aspect-ratio: 1 / 1;
  background: hsl(27.86deg 46.88% 45.84% / 75%);
  border-radius: 100%;
  height: 48px;
  width: 48px;
}

/* Stars */
#stars {
  inset: 60px 0 0 0;
  opacity: calc(50% - var(--light));
  position: fixed;
  z-index: -1;
}

#stars circle {
  animation: fade var(--animdur) linear infinite;
}

#stars line {
  opacity: 0.1;
}

@keyframes fade {
  0%, 100% { opacity: 0.25 }
  50% { opacity: 1 }
}
</style>


  
  
</head>

<body>
  <svg id="stars" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 1000 1000"></svg>

<label class="daynight">
  <input type="range" min="0" max="100" value="80" id="daynight" class="daynight-input">
  <span class="daynight-icons">
    <svg viewBox="0 0 24 24">
      <path d="M3 17h1m16 0h1m-15.4 -6.4l.7 .7m12.1 -.7l-.7 .7m-9.7 5.7a4 4 0 0 1 8 0"></path>
      <path d="M3 21l18 0"></path>
    </svg>
    <svg viewBox="0 0 24 24">
      <path d="M12 12m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0"></path>
      <path d="M3 12h1m8 -9v1m8 8h1m-9 8v1m-6.4 -15.4l.7 .7m12.1 -.7l-.7 .7m0 11.4l.7 .7m-12.1 -.7l-.7 .7"></path>
      </svg>
    <svg viewBox="0 0 24 24">		
      <path d="M14.828 14.828a4 4 0 1 0 -5.656 -5.656a4 4 0 0 0 5.656 5.656z"></path>
      <path d="M6.343 17.657l-1.414 1.414"></path>
      <path d="M6.343 6.343l-1.414 -1.414"></path>
      <path d="M17.657 6.343l1.414 -1.414"></path>
      <path d="M17.657 17.657l1.414 1.414"></path>
      <path d="M4 12h-2"></path>
      <path d="M12 4v-2"></path>
      <path d="M20 12h2"></path>
      <path d="M12 20v2"></path>
    </svg>
      <svg viewBox="0 0 24 24".........完整代码请登录后点击上方下载按钮下载查看

网友评论0