• JavaScript 经典代码(9)


    <style>
    BODY {
     FONT-SIZE: 9pt;
    }
    TD {
     FONT-SIZE: 9pt; LINE-HEIGHT: 11pt;
    }
    input {
     FONT-SIZE: 9pt;
    }
    SELECT {
     FONT-SIZE: 9pt; TEXT-ALIGN: center; WIDTH: 100px;
    }
    span {
     FONT-SIZE: 12pt;
    }
    </style>

    <script language=JavaScript>
    /*
    All Files are Designed & Writen by Windy_sk, you can use it freely but ...
    YOU MUST KEEP THIS ITEM !
    Email: <a href="mailto:windy_sk@126.com">windy_sk@126.com</a>
    */

    window.onload = function(){
     var color_list = new Array();
     var hex = new Array(6);
     var CurColor;
     var CurIndex;
     hex[0] = "FF"
     hex[1] = "CC"
     hex[2] = "99"
     hex[3] = "66"
     hex[4] = "33"
     hex[5] = "00"
     for(var x=0;x<6;x++){
      for(var y=0;y<6;y++){
       for(var z=0;z<6;z++){
        CurColor = hex[x] + hex[y] + hex[z];
        CurIndex = color_start.options.length;
        color_start.options[CurIndex] = new Option("",CurColor);
        color_start.options[CurIndex].style.backgroundColor = "#"+ CurColor;
        CurIndex = color_end.options.length;
        color_end.options[CurIndex] = new Option("",CurColor);
        color_end.options[CurIndex].style.backgroundColor = CurColor;
       }
      }
     }
    }

    function Dec2Any(str,num){
     if(!/\d+/.test(str)) return NaN;
     if(!/\d+/.test(num)) return NaN;
     var num=eval(num);
     if(num>36 || num<2)  return NaN;
     var the_str="0123456789abcdefghijklmnopqrstuvwxyz";
     var str=eval(str);
     var residue=0;
     var result="";
     while(true){
      residue=str%num;
      result = the_str.charAt(residue) + result;
      if(str<num) break;
      str=Math.floor(str/num);
     }
     return(result);
    }

    function get_color(the_num){
     if(the_num > 255) the_num = 255;
     if(the_num < 0)   the_num = 0;
     var the_color = Dec2Any(the_num,16);
     if(the_color.length==1) the_color = "0" + the_color;
     return the_color;
    }

    function build_text(str,C_start,C_end){
     var the_len = str.length;
     var R_start = eval("0x" + C_start.substr(0,2));
     var R_end = eval("0x" + C_end.substr(0,2));
     var R_unit = Math.floor((R_start - R_end)/the_len);
     var G_start = eval("0x" + C_start.substr(2,2));
     var G_end = eval("0x" + C_end.substr(2,2));
     var G_unit = Math.floor((G_start - G_end)/the_len);
     var B_start = eval("0x" + C_start.substr(4,2));
     var B_end = eval("0x" + C_end.substr(4,2));
     var B_unit = Math.floor((B_start - B_end)/the_len);
     var CurColorStr = "";
     var ResultStr = "";
     var tmp;
     show.value  = "";
     for(var i=0;i<the_len;i++){
      CurColorStr = "#";
      CurColorStr += get_color(R_start - i * R_unit);
      CurColorStr += get_color(G_start - i * G_unit);
      CurColorStr += get_color(B_start - i * B_unit);
      ResultStr   += "<font color='"+CurColorStr+"'>"+str.substr(i,1)+"</font>";
      show.value  += "<font color='"+CurColorStr+"'>"+str.substr(i,1)+"</font>\n";
     }
     return ResultStr;
    }

    function BuildIt(){
     clearInterval(flash_timer);
     ShowText.innerHTML = build_text(the_text.value,color_start.value,color_end.value);
     if(flash.checked) Flash_text();
    }

    var flash_timer = null;
    var color_list  = null;

    function Flash_text(){
     var obj_list = ShowText.children;
     color_list   = new Array();
     for(var i=0;i<obj_list.length;i++){
      color_list[color_list.length] = ShowText.children[i].color;
     }
     flash_timer = setInterval("FlashIt()",50);
    }

    function FlashIt(){
     var tmp_arr = new Array();
     for(var i=0;i<color_list.length-1;i++){
      tmp_arr[i+1] = color_list[i];
     }
     tmp_arr[0] = color_list[i];
     color_list = tmp_arr;
     for(var i=0;i<color_list.length;i++){
      ShowText.children[i].color = color_list[i];
     }
    }

    </script>

    <table>
      <tr>
        <td colspan=3>显示文字: <input id=the_text type=text size=50 value="彩虹文字彩虹文字彩虹文字彩虹文字彩虹文字"></td>
      </tr>
      <tr>
        <td>起始颜色: <select id="color_start" onChange="BuildIt();the_text.focus()"></select></td>
        <td> ---- </td>
        <td>结束颜色: <select id="color_end" onChange="BuildIt();the_text.focus()"></select></td>
      </tr>
      <tr>
        <td colspan=3><input id=flash type=checkbox onclick="this.checked?Flash_text():clearInterval(flash_timer)"><label for=flash>闪烁</label></td>
      </tr>
    </table>
    <span id=ShowText style=""></span>
    <br>
    <textarea id=show rows=15 cols=50></textarea>

  • 相关阅读:
    明明已经include_once() 但还是报错Class 'XXXXXControllerTOPData' not found
    dell U2515H 2k显示器黑屏问题,dp线问题。
    centos7.4 php5升级到php7
    thinkphp批量插入 更新sql
    查询速度慢了10倍,查询条件类型不对,字符串当做数字类型。
    margin-left:auto;margin-right:auto; 不起作用的原因
    jquery 查找元素,id,class
    php分割url,获取参数query
    阿里云服务器删除日志的方法,查看有哪些大文件
    sql优化 分字段统计查询
  • 原文地址:https://www.cnblogs.com/MaxIE/p/305077.html
Copyright © 2020-2023  润新知