html输入范围拇指平滑运动

Phi*_*les 5 html css forms input

我有一个HTML输入范围设置与外观的一堆CSS更改,我想知道是否有任何方法使它从任何地方顺利更改到用户更改的位置?

input[type=range] {
        -webkit-appearance: none;
        width: 100%;
        height: 20px;
        border-radius: 5px;
        border: 1px solid;
        background: none;
        box-shadow: 0px 0px 8px 0px #555, 0px 0px 25px 0px #555 inset;
        transition: 0.4s all ease-out;
        outline: none;
    }

    input[type=range]::-webkit-slider-thumb {
        -webkit-appearance: none;
        width: 30px;
        height: 30px;
        background-color: #CCC;
        border: solid 1px #333;
        border-radius: 4px;
        box-shadow: 0px 0px 8px 0px #555, 0px 0px 25px 0px #555 inset;
        cursor: pointer;
        transition: 0.4s all ease-out;
    }

    input[type=range]:hover {
        background: rgba(255, 255, 255, 0.2);
        box-shadow: 0px 0px 13px 0px #444, 0px 0px 20px 0px #444 inset;
    }

    input[type=range]:hover::-webkit-slider-thumb {
        border: solid 1px #444;
        box-shadow: 0px 0px 15px 0px #444, 0px 0px 20px 0px #444 inset;
    }

    input[type=range]:focus {
        background: rgba(255, 255, 255, 0.4);
        box-shadow: 0px 0px 18px 0px #333, 0px 0px 15px 0px #333 inset;
    }

    input[type=range]:focus::-webkit-slider-thumb {
        border: solid 1px #333;
        box-shadow: 0px 0px 22px 0px #333, 0px 0px 15px 0px #333 inset;
    }
Run Code Online (Sandbox Code Playgroud)
<input type="range" id="brightness_slider" value="90" step="1" min="30" max="100">
Run Code Online (Sandbox Code Playgroud)

Fen*_*ton 5

这些是影响平滑度的因素:

  1. 横幅的宽度
  2. 最小/最大范围
  3. 步长大小

所以如果你有:

  1. 1000px宽范围输入
  2. 0 - 1000 范围
  3. 步长为 1

每一步都只有 1px,而且会非常平滑。

如果你有:

  1. 1000px宽范围输入
  2. 0 -100 范围
  3. 步长为 25

它将在允许的值之间对齐,显得不那么流畅。

这实际上是步长和范围之间相互作用的一个特征,并为用户提供了关于可接受值的有用反馈。

  • 我们如何添加一个过渡,以便当它移动到下一步时,它能够顺利而不是瞬间完成。 (6认同)