1

我必须设置特定选项卡的渐变颜色。它包含从第一个选项卡到最后一个选项卡的渐变颜色。我该如何设置。为此,我使用了以下代码

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

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

但问题是一个标签只包含一种颜色。我想要从第一个到最后一个标签的渐变色。我该怎么做?

4

1 回答 1

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/

于 2013-04-29T06:40:44.007 回答