我尝试使用librery roundSlider.js创建一个圆形滑块,它在路径中有一个多色的背景。我尝试使用线性渐变,但结果不好,因为当我开始使用hadler移动滑块时,背景颜色开始移动,有些颜色消失了。
这是我的代码:
$(document).ready(function () {
$("#shape").roundSlider({
radius: 80,
width: 8,
min: 0,
max: 100,
handleSize: "+16",
circleShape: "pie",
handleShape: "dot",
sliderType: "min-range",
startAngle: 315,
value: 24,
disabled: false
});
});
.rs-range-color {
background: linear-gradient(to right, yellow 20%, blue 20%, blue 40%, red 40%, red 60%, green 60%, green 80%, brown 80%, brown 100%);
}
.rs-path-color {
/*background-color: #C2E9F7;*/
background: linear-gradient(to right, yellow 20%, blue 20%, blue 40%, red 40%, red 60%, green 60%, green 80%, brown 80%, brown 100%);
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
.rs-handle {
background-color: #C2E9F7;
padding: 7px;
border: 2px solid #C2E9F7;
}
.rs-handle.rs-focus {
border-color: #33B5E5;
}
.rs-handle:after {
border-color: #33B5E5;
background-color: #33B5E5;
}
.rs-border {
border-color: transparent;
}
.rs-tooltip-text {
font-family: Roboto, sans-serif;
font-size: 20px;
border-radius: 7px;
transition: background 0.02s ease-in-out;
color: #33B5E5;
}
.rs-tooltip-text:before {
position: absolute;
left: -10px;
top: -18px;
content: 'DISCOUNT';
font-size: 12px;
}
.rs-tooltip-text:after {
position: absolute;
left: 10px;
top: 48px;
content: '';
font-size: 12px;
}
.container{
position: absolute;
z-index: 2;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: Roboto, sans-serif;
padding: 20px;
border: 1px solid;
}
/* Solution for inner circle with shadow */
#shape:after {
content: " ";
display: block;
height: calc(100% - 40px); /* here 40 is the gap between the outer and inner circle */
width: calc(100% - 40px);
position: absolute;
top: 20px; /* divide the gap value by 2 */
left: 20px;
z-index: 9; /* tooltip z-index is 10, so we put less than that value */
border-radius: 1000px;
box-shadow: 0 0 10px -2px;
}
/* Solution for bottom triangle out issue */
#shape .rs-overlay {
height: calc(50% + 5px);
width: calc(50% + 5px);
top: -5px;
left: -5px;
border-radius: 1000px 0 0 0;
}
<!DOCTYPE html>
<html>
<head>
<title>RoundSlider - A sample testing</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/roundslider.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/roundslider.min.js"></script>
</head>
<body style="padding: 10px 0 0 20px; font-family: monospace;">
<div class="container">
<div class="control">
<div id="shape"></div>
</div>
</div>
</body>
<html>
当你运行上面的代码时,你可以看到路径的背景颜色随着我移动处理程序而移动,这就是问题所在。我希望背景保持固定。换句话说,我希望背景路径是一个有3种或更多颜色的渐变,并且这个背景覆盖了滑块的100%。我不希望颜色移动或被移除,为其他颜色让路。
2条答案
按热度按时间50pmv0ei1#
在roundSlider中,**
svgMode
**在滑动条由SVG元素构成的情况下可用。因此,使用它可以将SVG渐变应用于range和path元素。此外,这里这些元素是单个元素,因此您不会遇到此问题。在这里,我已经根据您的场景更新了演示,请检查以下内容:
https://jsfiddle.net/soundar24/6se2tmp9/
在这个演示中,我没有设置
pathColor
,因为如果rangeColor
和路径颜色都相同,那么你不会发现任何差异。此外,由于这只是默认的SVG渐变,因此可以根据您的需求修改此SVG线性渐变。
编辑1:
根据你的评论,那么你需要使用圆锥曲线渐变。在SVG中没有明确的圆锥曲线渐变选项,但你仍然可以找到实现它的方法。
1.或者,我使用CSS圆锥渐变来实现这一点。查看下面的演示:
https://jsfiddle.net/soundar24/6se2tmp9/2/
1.另外,我还做了一个变通方案,在roundSlider路径上创建SVG范围段。这也与您的要求相似。请查看下面的演示:
https://jsfiddle.net/soundar24/8pgo9ce7/
6qqygrtg2#