移动的彩虹

 <html>
 <head>
  <style>
   #bg{
    position:absolute;
    left:0;
    top:0;
    width:100%;
    height:100%;
    background:#000;
    font-size:40px;
    color:#ccc;
    text-align:center;
   }
   
   #colorLine{
    width:400px;
   }

   #colorLine div{
    width:5px;
    height:2px;
    float:left;
    overflow:hidden;
   }
  </style>
 </head>
<body>
 <table id="bg">
  <tr height="300">
   <td>
    彩虹进度条
   </td>
  </tr>
  <tr  height="100">
   <td align=center>
    <div id="colorLine">
    </div>
   </td>
  </tr>
  <tr>
   <td></td>
  </tr>
 </table>
</body>
</html>

<script>
 var IE6 = navigator.userAgent.toLowerCase().indexOf('ie')+1 &&
/MSIE (5\.5|6\.)/i.test(navigator.userAgent);
 var CL = document.getElementById('colorLine');
 
 //创建彩虹条
 function makeCLine(){
  
  var r = 255;
  var g = 0;
  var b = 0;
  var step = 1;
  
  // 1. 增加绿色
  // 2. 减少红色
  // 3. 增加蓝色
  // 4. 减少绿色
  for(var i = 0; i < 80; i ++ ){
     var node = document.createElement('div');
     if(g > 255 && step == 1)
      step = 2;
     if(r < 0 && step == 2)
      step = 3;
     if(b > 255 && step == 3)
      step = 4;
     node.style.backgroundColor = 'rgb(' + r + ',' + g + ',' + b + ')';
     CL.appendChild(node);
     if(step == 1)
     g += 14;
     if(step == 2)
     r -= 14;
     if(step == 3)
     b += 14;
     if(step == 4)
     g -= 14;
  }
  
  var oNodeL = IE6 ? CL.firstChild : CL.firstChild.nextSibling;
  var oNodeR = CL.lastChild;

  //制作两端渐变效果
     for(var i = 0; i < 20; i ++ ){
      oNodeL.style.cssText += ';opacity:'+ (0.05 * i) +
';filter:Alpha(Opacity=' + (0.05 * i * 100) +')';
      oNodeR.style.cssText += ';opacity:'+ (0.05 * i) +
';filter:Alpha(Opacity=' + (0.05 * i * 100) +')';

        oNodeL = oNodeL.nextSibling;
         oNodeR = oNodeR.previousSibling;
     }
 }


//移动彩虹条
function makeCLMove()
{
   var colors = [];
   for(var i = CL.lastChild; i; i = i.previousSibling)
   {
      if(i.style)
      colors.unshift(i.style.backgroundColor);
   }
   var flag = 1;
   var j = 0;
   setInterval(function()
   {
      var sTempColor = CL.lastChild.style.backgroundColor;
      var oNodeL = IE6 ? CL.firstChild : CL.firstChild.nextSibling;
      for(var i = CL.lastChild; i; i = i.previousSibling)
      {
         if(i.previousSibling && i.previousSibling.style)
         i.style.backgroundColor = i.previousSibling.style.backgroundColor;
      }
      if(j > (colors.length - 1))
       flag = 0;
      else if(j < 1)
       flag = 1;
      oNodeL.style.backgroundColor = flag ? colors[j ++ ] : colors[j -- ];
   }, 1);
}

makeCLine();
makeCLMove();
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值