你可以使用图像作为HTML滑块的背景吗?

时间:2016-10-25 23:26:55

标签: javascript jquery html css

我想使用灰度图像作为背景,以便用户可以通过修改滑块来输入灰度强度。但我不确定是否可能或如何做到这一点。谢谢。

有点像这样: enter image description here

1 个答案:

答案 0 :(得分:1)

您可以设置拇指和曲目的样式,但几乎所有浏览器都使用不同的CSS。有关详细信息,请参阅https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/

input[type=range]::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  width: 100%;
  height: 15px;
  background: linear-gradient(to right, black, white);
  border: 2px solid grey;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  border: none;
  height: 40px;
  width: 40px;
  border-radius: 20px;
  background-color: blue;
  cursor: pointer;
}

https://jsfiddle.net/vms19x32/