js+svg实现辣椒滑竿滑块取值器效果代码
代码语言:html
所属分类:其他
代码描述:js+svg实现辣椒滑竿滑块取值器效果代码,点击辣椒进行拖拽移动。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #fff; font-size: 3em; } .slider-wrapper { --slider-height: .3125em; --slider-thumb-size: 1.75em; --slider-progress: 50; border-radius: 50px; width: 7em; max-width: 100%; transition: width 0.2s; } .slider-wrapper.unlocked { width: 8em; } .slider-track { display: flex; justify-content: center; align-items: center; position: relative; border-radius: inherit; width: 100%; height: var(--slider-height); background-image: linear-gradient(to right, transparent 0% calc(var(--slider-progress) * 1%), #aaa calc(var(--slider-progress) * 1%) 100%), linear-gradient(to right, #62ad1d, #fbbd1e, #fb6e1e, #e71a1a, #220000); background-size: auto, 125% 100%; box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.6), inset 0 -2px 4px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.1); transition: background-size 0.2s; } .slider-wrapper.unlocked > .slider-track { background-size: auto, 100% 100%; } .slider-input { -moz-appearance: none; -webkit-appearance: none; appearance: none; position: absolute; z-index: 1; left: 50%; transform: translate(-50%); border-radius: inherit; width: calc(100% + var(--slider-thumb-size)); height: 100%; opacity: 0; cursor: pointer; } .slider-input::-webkit-slider-runnable-track { height: 100%; } .slider-input::-webkit-slider-thumb { -moz-appearance: none; -webkit-appearance: none; appearance: none; margin-top: calc((var(--slider-height) / 2) - (var(--slider-thumb-size) / 2)); border-width: 0; border-radius: 50%; width: var(--slider-thumb-size); height: var(--slider-thumb-size); } .slider-input::-moz-range-thumb { -moz-appearance: none; -webkit-appearance: none; appearance: none; margin-top: calc((var(--slider-height) / 2) - (var(--slider-thumb-size) / 2)); border-width: 0; border-radius: 50%; width: var(--slider-thumb-size); height: var(--slider-thumb-size); } .slider-thumb { display: flex; justify-content: center; align-items: center; position: absolute; left: calc(var(--slider-progress) / 100 * (100% - var(--slider-height)) + var(--slider-height) / 2); left: calc(var(--slider-progress) * 1%); transform: translateX(-50%); width: var(--slider-thumb-size); height: var(--slider-thumb-size); transition: transform 0.2s; } .slider-input:active + .slider-thumb { transform: translateX(-50%) scale(0.86); } .slider-thumb::after { content: ""; position: absolute; z-index: 1; width: 150%; height: 150%; background-image: url("https://assets.codepen.io/4175254/explosion-2.png"); background-size: 800%; opacity: 0; } .slider-thumb.play-explosion::after { animation: explosion 0.5s steps(8) forwards; opacity: 1; } @keyframes explosion { to { background-position-x: -800%; } } .slider-thumb-image { --slider-thumb-image-color: rgb(251 150 30); position: relative; width: 100%; height: 100%; fill: var(--slider-thumb-image-color); transition: transform 0.2s; } .slider-thumb-image.shake { animation: shake 0.2s infinite; } @keyframes shake { 0% { transform: rotate(0deg); } 25% { transform: rotate(5deg); } 50% { transform: rotate(0eg); } 75% { transform: rotate(-5deg); } 100% { transform: rotate(0deg); } } </style> </head> <body> <!-- Keep dragging over the maximum value unlock a secret level --> <div class="slider-wrapper"> <div class="slider-track"> <input class="slider-input" type="range" value="100"> <div class="slider-thumb"> <svg class="slider-thumb-image" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 176 176"> <path d="M109.621 58.624c-2.248-1.8-5.008-2.962-7.793-3.69-55.136-14.399-18.22 90.985-88.17 59.012-.306-.14-.621-.334-.907-.511-3.895-2.411-8.839 1.419-6.676 5.669 37.499 73.676 140.46-6.692 111.993-50.336-1.504-2.305-3.109-4.594-4.889-6.692a25.95 25.95 0 0 0-3.558-3.453z" filter="url(#A)"/> <path d="M108.983 52.653c-15.728-4.464-34.22 2.06-36.123 4.369 14.141-.161 22.213-.751 29.185 10.25 12.719-.852 17.221 3.27 24.322 18.322 1.953-14.872-6.86-27.522-12.263-30.83 14.395-43.021.099-41.872-10.808-39.269 9.985 19.97 9.585 27.874 5.687 37.158z" fill="#35890e" filter="url(#B)"/> <path d="M80.361 65.109c4-4.4 8.333-.833 10 1.5-8.799-3.2-18.667 17.667-22.501 28.5 2.5-8.167 8.501-25.6 12.501-30z" fill="#fff" fill-opacity=".4"/> <defs> <filter id="A" x="3.547" y="49.575" width="124.432" height="107.417" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB"> <feFlood flood-opacity="0"/> <feBlend in="SourceGraphic" result="B"/> <feColorMatrix in="SourceAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="C"/> <feOffset dx="-2" dy="-4"/> <feGaussianBlur stdDeviation="10"/> <feComposite in2="C" operator="arithm.........完整代码请登录后点击上方下载按钮下载查看
网友评论0