2017-05-08 83 views
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/

+0

插入代碼,除去健談文本 – JimHawkins

回答

0

最後,我做到了......

  1. 我們需要有關附加梯度或新的div忘記。從你的代碼中刪除這個。
  2. 在小部件初始化後,我們需要爲我們的塊添加新類(請參見第9行)。
  3. 通過css(之前/之後)在新課堂中處理一些魔法。

http://jsfiddle.net/LLfWd/624/$(this).addClass("ui-slider-multiple");