2013-04-29 76 views
1

我必須設置特定選項卡的漸變顏色。它包含從第一個選項卡到最後一個選項卡的漸變顏色。如何設置此選項。 對於我用下面的代碼如何爲選項卡設置漸變顏色?

$(function() { 
    $("#tabs").tabs(); 

     $('.gradient_me').each(function(index) { 
      var color = 255-index*75; 
      $(this).css('background', 'rgb('+color+', 0, 0)'); 
     }); 
    }); 

但問題是一個選項卡只包含一個color.I要從第一漸變色到最後我tab.How能做到這一點?

+0

'但問題是一個選項卡只包含一個color.' u能闡述這個..我檢查了小提琴和標籤頭有3種不同的顏色 – bipen 2013-04-29 05:28:24

+0

@ bipen,我想漸變顏色爲每個選項卡。在演示中,您可以看到選項卡漸變。但在選項卡內,它不是 – Niths 2013-04-29 05:30:34

回答

2

簡單!

所有你需要的是一個線性漸變CSS規則。

$(function() { 
    $("#tabs").tabs(); 

     $('.gradient_me').each(function(index) { 
      var color = 'rgb(' + (255-index*75) + ', 0, 0)'; 
      var color2 = 'rgb(' + (255-index*75 - 75) + ', 0, 0)'; 
      $(this).css('background', '-moz-linear-gradient(left, '+color+', ' + color2 +')'); 
      $(this).css('background', '-webkit-linear-gradient(left, '+color+', ' + color2 +')'); 
      $(this).css('background', '-ms-linear-gradient(left, '+color+', ' + color2 +')'); 
      $(this).css('background', '-o-linear-gradient(left, '+color+', ' + color2 +')'); 
      $(this).css('background', 'linear-gradient(left, '+color+', ' + color2 +')'); 

     }); 
    }); 

演示:http://jsfiddle.net/5zfyU/8/

+0

@ lolmaus-我想將顏色從紅色替換爲灰色。 – Niths 2013-04-29 06:47:58

+0

你想讓我爲你編碼嗎?我給你提示如何做你想做的事情。代碼可以很容易地適應您的需求。要麼自己做,要麼做另一份你勝任的工作。 – 2013-04-29 07:48:46

相關問題