div+css+js实现多边形线条自定义参数调整效果代码

代码语言:html

所属分类:其他

代码描述:div+css+js实现多边形线条自定义参数调整效果代码

代码标签: div css js 多边形 线条 自定义 参数 调整

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

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

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

  
<style>
body, html {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background-color: #f5f5f5;
}

#main-container {
  display: flex;
  height: 100%;
}

#pattern-container {
  flex: 1;
  position: relative;
}

#controls-container {
  width: 25%;
  padding: 20px;
  background-color: #fff;
  box-shadow: -5px 0 10px rgba(0, 0, 0, 0.1);
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
  overflow-y: auto;
  border-radius:.5em;
  margin:.75em;
}

.control {
  display: flex;
  flex-direction: column;
}

label {
  font-size: 14px;
  margin-bottom: 12px;
  color: #333;
}

input[type="range"] {
  width: 100%;
  -webkit-appearance: none;
  background: #ddd;
  outline: none;
  height: 2px;
  transition: all 0.3s ease;
}

input[type="range"]:hover {
  background: #ccc;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: #333;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.3s ease;
}

input[type="range"]:hover::-webkit-slider-thumb {
  background: #FF5722;
}

input[type="range"]:active::-webkit-slider-thumb {
  background: #FF5722;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #333;
}

input:checked + .slider:before {
  transform: translateX(26px);
}

#shuffle {
  background-color: #333;
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

#shuffle:hover {
  background-color: #555;
}

/* Dot grid background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: radial-gradient(circle, #ccc 1px, transparent 1px);
  background-size: 20px 20px;
  opacity: 0.5;
  z-index: -1;
}

@media (max-width: 768px) {
  #main-container {
    flex-direction: column;
  }
  
  #controls-container {
    width: 100%;
    grid-template-columns: repeat(2, 1fr);
  }
}
</style>

  
</head>

<body translate="no">
  <div id="main-container">
  <div id="pattern-container"></div>
  <div id="controls-container">
    <div class="control">
      <label for="points">Points</label>
      <input type="range" id="points" min="3" max="20" value="6">
    </div>
    <div class="control">
      <label for="chaos">Chaos</label>
      <input type="range" id="chaos" min="0" max="100" value="0">
    </div>
    <div class="control">
      <label for="rotation">Rotation</label>
      <input type="range" id="rotation" min="0" max="360" value="0">
    </div>
    <div class="control">
      <label for="hue">Hue</label>
      <input type="range" id="hue" min="0" max="360" value="0">
    </div>
    <div class="control">
      <label for="saturation">Saturation</label>
      <input type="range" id="saturation" min="0" max="100" value="50">
    </div>
    <div class="control">
      <label for="lightness">Lightness</label>
      <input type="range" id="lightness" min="0" max="100" value="50">
    </div>
    <div class="control">
      <label for="roundness">Roundness</label>
      <input type="range" id="roundness" min="0" max="100" value="0">
    </div>
    <div class="control">
      <label for="stroke-width">Stroke Width</label>
      <input type="range" id="stroke-width" min="1" max="48" value="2">
    </div>
    <div class="control">
      <label for="fill">Fill</label>
      <label class="switch">
        <input type="checkbox" id="fill">
        <span class="slider"></span>
      </label>
    </div>
    <button id="shuffle">Shuffle Controls</button>
  </div>
</div>
  
      <script  >
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
const patternContainer = document.getElementById("pattern-container");
patternContainer.appendChild(svg);

const controls = {
  points: document.getElementById("points"),
  chaos: document.getElementById("chaos"),
  rotation: document.getElementById("rotation"),
  hue: document.getEleme.........完整代码请登录后点击上方下载按钮下载查看

网友评论0