2016-11-05 50 views
5

我有一個HTML輸入範圍設置了一堆CSS外觀變化,我想知道是否有任何方法可以使它從任何地方平滑地更改到用戶更改的位置?html輸入範圍大拇指平滑運動

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; 
 
    }
<input type="range" id="brightness_slider" value="90" step="1" min="30" max="100">

回答

1

這些都是影響的平滑的東西:

  1. 橫幅的寬度
  2. 最小/最大範圍
  3. 步驟
  4. 大小

所以,如果您有:

  1. 1000像素寬範圍的輸入
  2. 0 - 1000範圍
  3. 步長

1每一步都將只是1px的,這將是相當流暢。

如果你有:

  1. 1000像素寬範圍的輸入
  2. 0 -100範圍
  3. 步驟25

大小將允許值之間咬合,出現較少的流體。

這實際上是您的步長和您的範圍之間的相互作用的一個特徵,並提供了有用的反饋給用戶可接受的值。