0
我想有2個範圍,創建滑塊,並添加一些顏色到背景,它與最大值100(9號線)OK:jQuery UI的滑塊與多個範圍的背景錯誤
$(function() {
// the code belows assume the colors array is exactly one element bigger than the handlers array.
var handlers = [20, 40, 60, 80];
var colors = ["#ff0000", "#00ff00", "#0000ff", "#00ffff", "#00A3A3"];
updateColors(handlers);
$("#slider").slider({
min: 0,
max: 100, // change to 95 causes problems
values: handlers,
slide: function (evt, ui) {
for(var i = 0, l = ui.values.length; i < l; i++){
if(i !== l-1 && ui.values[i] > ui.values[i + 1]){
return false;
}
else if(i === 0 && ui.values[i] < ui.values[i - 1]){
return false;
}
}
updateColors(ui.values);
}
});
function updateColors(values) {
var colorstops = colors[0] + ", "; // start left with the first color
for (var i=0; i< values.length; i++) {
colorstops += colors[i] + " " + values[i] + "%,";
colorstops += colors[i+1] + " " + values[i] + "%,";
}
// end with the last color to the right
colorstops += colors[colors.length-1];
/* Safari 5.1, Chrome 10+ */
var css = '-webkit-linear-gradient(left,' + colorstops + ')';
$('#slider').css('background-image', css);
}
});
問題出現變化後,它,從最高:100至最高:95:http://jsfiddle.net/LLfWd/623/
插入代碼,除去健談文本 – JimHawkins