0
$('.StandardColor').click(function() {
var SelectedCol = $('.StandardColor').attr(data - color);
alert(SelectedCol)
FillScrollColor(SelectedCol)
});
function FillScrollColor(SelectedColor) {
var rgb = hexToRgbA(SelectedColor);
$('#range_4').css({
'background': 'linear-gradient(to right, rgba(2, 1, 2, 1) 0%,' + rgb + '100%)'
})
}
$("#range_4").slider({
range: "min",
max: 100,
value: 50,
slide: function(e, ui) {
// How to pick the color!!
}
});
function hexToRgbA(hex) {
var c;
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
c = hex.substring(1).split('');
if (c.length == 3) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
}
c = '0x' + c.join('');
return 'rgba(' + [(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') + ',1)';
}
throw new Error('Bad Hex');
}
.color {
display: block;
width: 20px;
height: 20px;
float: left;
margin-right: 5.5px;
cursor: pointer;
}
.colors_range_row {
display: block;
position: relative;
margin-top: 30px;
width: 100%;
padding: 0px;
}
#range_4 {
height: 12px;
width: 95%;
background: rgba(2, 1, 2, 1);
background: -moz-linear-gradient(left, rgba(2, 1, 2, 1) 0%, rgba(103, 56, 111, 1) 100%);
background: -webkit-gradient(left top, right top, color-stop(0%, rgba(2, 1, 2, 1)), color-stop(100%, rgba(103, 56, 111, 1)));
filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#020102', endColorstr='#67386f', GradientType=1);
}
.clearfix {
clear: both;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/2.0.0/themes/base/jquery-ui.css">
<div class="row">
<span class="color StandardColor" style="background: #000" data-color="000"></span>
<span class="color StandardColor" style="background: #4a4a4a" data-color="4a4a4a"></span>
<span class="color StandardColor" style="background: #417505" data-color="417505"></span>
<span class="color StandardColor" style="background: #4a90e2" data-color="4a90e2"></span>
<span class="color StandardColor" style="background: #8a4ebf" data-color="8a4ebf"></span>
<span class="color StandardColor" style="background: #c0202a" data-color="c0202a"></span>
<span class="color StandardColor" style="background: #f5a623" data-color="f5a623"></span>
<span class="color StandardColor" style="background: #f8e71c" data-color="f8e71c"></span>
<span class="color StandardColor empty" data-color="ffffff"></span>
</div>
<br>
<br>
<br>
<div class="colors_range_row">
<div id="range_4" class="range"></div>
<div class="clearfix"></div>
</div>
<div class="clearfix"></div>
我想達到以下
用戶可以從給定的範圍
選擇任何顏色的挑選在選擇(單擊)顏色時,滑塊會感覺到各自的顏色(暗到淡)
如果用戶滑動滑塊,各個框下滑塊獲取的充滿了各自的尖色
如下圖所示
所以懇請指導我如何能我也一樣。
以下是我的代碼相同。
<div class="colors_range_row">
<div id="range_4" class="range"></div>
<div class="clearfix"></div>
</div>
<script>
$('.colorBox').click(function() {
var SelectedCol = $('.StandardColor').attr('data-color');
FillScrollColor(SelectedCol)
});
function FillScrollColor(SelectedColor) {
var rgb = hexToRgbA(SelectedColor);
$('#range_4').css({ 'background': 'linear-gradient(to right, rgba(2, 1, 2, 1) 0%,' + rgb + '100%)' })
}
$("#range_4").slider({
range: "min",
max: 100,
value: 50,
slide: function(e, ui) {
// How to pick the color!!
}
});
</script>
而我迷失在如何從滑塊中挑選顏色。 ??
你能爲你的演示提供更多的html,所以我可以模擬它 – DobromirM
希望它能幫助你一點。 –