shawl.qiu Javascript 渐隐渐显类 Faded V1.0
说明:
嗯, 这个呢, 最近在了解色彩学, 所以陆续会弄一些与色彩相关的东西.
比如整理一些与色彩相关的资料汇编成册, 学习与色彩相关的心理感受, 调色技巧等.
目录:
1. 调用
1.1 调用 1
1.2 调用 2
2. 类 Faded
shawl.qiu
2007-06-20
http://blog.csdn.net/btbtd
演示1: http://files.myopera.com/btbtd/javascript/class/faded/Faded_v1-0.htm
演示2: http://files.myopera.com/btbtd/javascript/class/faded/Faded_v1-0_demo_1.htm
下载: http://files.myopera.com/btbtd/javascript/class/faded/Faded_v1-0.7z
内容:
1. 调用
1.1 调用 1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <!-- DW6 -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>shawl.qiu template</title>
- <style type="text/css">
- /* <![CDATA[ */
- div{margin:1px; vertical-align:middle;}
- .FadeId18Class
- {
- color:white;
- }
- .FadeId18OverClass
- {
- color:#D369A4;
- }
- /* ]]> */
- </style>
- </head>
- <body>
- <table border="0" align="center" cellpadding="4" cellspacing="4">
- <tr align="center" valign="middle">
- <td><div id="FadeId1" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId2" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId3" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId4" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId5" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div id="FadeId6" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId7" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId8" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId9" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId10" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div id="FadeId11" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId12" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId13" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId14" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId15" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div id="FadeId16" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId17" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId18" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId19" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId20" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div id="FadeId21" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId22" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId23" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId24" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div id="FadeId25" style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- </table>
- <script type="text/javascript" src="Faded_v1-0.js"></script>
- <script type="text/javascript">
- //<![CDATA[
- var Time = 20;
- var Interval = 5;
- var Fade = new Faded();
- Fade.Debug = false;
- /*
- function fAddElement
- (sId, sOriginColor, sOverColor, sOutColor, iTime, iIntervalMs, bCompColor, sClassName, sOverClassName)
- */
- Fade.Element.Add("FadeId1", "#C4D700", "#cccccc", false, Time, Interval);
- Fade.Element.Add("FadeId2", "#C80852", "#cccccc", false, Time, Interval);
- Fade.Element.Add("FadeId3", "#EA5520", "#cccccc", false, Time, Interval);
- Fade.Element.Add("FadeId4", "#F7AB00", "#cccccc", false, Time, Interval);
- Fade.Element.Add(document.getElementById("FadeId5"), "#B0DCD5", "#cccccc", false, Time, Interval);
- Fade.Element.Add("FadeId6", "#59C3E2", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId7", "#F0F8FF", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId8", "#134098", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId9", "#735B9F", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId10", "#C2737F", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId11", "#FFF8B1", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId12", "#3D7D53", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId13", "#ffffff", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId14", "#E5A96B", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId15", "#ADD8E6", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId16", "#002FA7", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId17", "#4C8DB5", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId18", "#527AA3", "#cccccc", false, Time, Interval, false,
- "FadeId18Class", "FadeId18OverClass");
- Fade.Element.Add("FadeId19", "#9D899D", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId20", "#6F196F", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId21", "#D369A4", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId22", "#BBA1CB", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId23", "#FFFF00", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId24", "#7BB99B", "#cccccc", false, Time, Interval, true);
- Fade.Element.Add("FadeId25", "#7E4985", "#cccccc", false, Time, Interval, true);
- Fade.Go();
- document.title = Fade.au.Subject+" "+Fade.au.Version;
- Fade = null;
- //]]>
- </script>
- </body>
- </html>
1.2 调用 2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <!-- DW6 -->
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>shawl.qiu template</title>
- <style type="text/css">
- /* <![CDATA[ */
- div{margin:1px; vertical-align:middle;}
- .FadeId18Class
- {
- color:white;
- }
- .FadeId18OverClass
- {
- color:#D369A4;
- }
- /* ]]> */
- </style>
- </head>
- <body>
- <table border="0" align="center" cellpadding="4" cellspacing="4" id="MainTable">
- <tr align="center" valign="middle">
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- <tr align="center" valign="middle">
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- <td><div style="width:100px; height:100px; background-color:#cccccc; ">shawl.qiu</div></td>
- </tr>
- </table>
- <script type="text/javascript" src="Faded_v1-0.js"></script>
- <script type="text/javascript">
- //<![CDATA[
- fSetAlternativeColorAndFading("MainTable", "div");
- function fSetAlternativeColorAndFading
- (
- sId,
- sSubTag,
- sBgColor1,
- sBgOverColor1,
- sClassName1,
- sOverClassName1,
- sBgColor2,
- sBgOverColor2,
- sClassName2,
- sOverClassName2,
- iTime,
- iIntervalMs,
- bByNode,
- bCompColor
- )
- {// shawl.qiu script
- var Obj = null;
- if(typeof(sId)=="string")
- {
- Obj = document.getElementById(sId);
- }
- if(Obj==null)
- {
- alert("主域为 null!");
- return;
- }
- if(!sBgColor1) sBgColor1 = "#ffffff";
- if(!sBgColor2) sBgColor2 = "#F5F5F5";
- if(!sBgOverColor1) sBgOverColor1 = "#cccccc";
- if(!sBgOverColor2) sBgOverColor2 = "#cccccc";
- if(!iTime) iTime = 20;
- if(!iIntervalMs) iIntervalMs = 5;
- if(!sClassName1) sClassName1 = "";
- if(!sOverClassName1) sOverClassName1 = "";
- if(!sClassName2) sClassName2 = "";
- if(!sOverClassName2) sOverClassName2 = "";
- var Debug = false;
- var ChildSet = null;
- if(bByNode)
- {
- ChildSet = Obj.childNodes;
- }
- else
- {
- ChildSet = Obj.getElementsByTagName(sSubTag);
- }
- var iCount = 0;
- var iLen = ChildSet.length;
- var iNodeCount = 1;
- if(Debug)
- {
- alert(ChildSet);
- alert
- (
- ""
- +"/n ChildSet.length: "+ChildSet.length
- +"/n iCount: "+iCount
- +"/n iNodeCount: "+iNodeCount
- );
- }
- var Fade = new Faded();
- while(iCount<iLen)
- {
- if(ChildSet[iCount].nodeType==1&&ChildSet[iCount].nodeName==(sSubTag.toUpperCase()))
- {
- if(iNodeCount%2==0)
- {
- /*
- function fAddElement
- (sId, sOriginColor, sOverColor, sOutColor, iTime, iIntervalMs, bCompColor, sClassName, sOverClassName)
- */
- Fade.Element.Add
- (
- ChildSet[iCount],
- sBgColor1,
- sBgOverColor1,
- sBgColor1,
- iTime,
- iIntervalMs,
- bCompColor,
- sClassName1,
- sOverClassName1
- );
- }
- else
- {
- Fade.Element.Add
- (
- ChildSet[iCount],
- sBgColor2,
- sBgOverColor2,
- sBgColor2,
- iTime,
- iIntervalMs,
- bCompColor,
- sClassName2,
- sOverClassName2
- );
- } // end if 1
- iNodeCount++;
- } // ne if
- iCount++;
- } // end while
- Fade.Go();
- Fade = null;
- } // end function fSetAlternativeColorAndFading
- //]]>
- </script>
- </body>
- </html>
2. 类 Faded
- // shawl.qiu JavaScript Document
- /*-----------------------------------------------------------------------------------*/
- * shawl.qiu Javascript Faded class v1.0
- /*-----------------------------------------------------------------------------------*/
- //---------------------------------begin class Faded()-------------------------------//
- function Faded()
- { // shawl.qiu code
- //------------------------------------begin public variable
- //---------------begin about
- this.au = {}
- this.au.Subject = "shawl.qiu Javascript Faded class";
- this.au.Version = "v1.0";
- this.au.Name = "shawl.qiu";
- this.au.Email = "shawl.qiu@gmail.com";
- this.au.Blog = "http://blog.csdn.net/btbtd";
- this.au.CreatedDate = "2007-6-19";
- this.au.Update = {};
- this.au.Update["1"] = "";
- //---------------end about
- this.Debug = false;
- this.Element = {}
- this.Element.Set = [];
- this.Element.Add = fAddElement;
- //------------------------------------end public variable
- //------------------------------------begin private variable
- var Tl = this;
- //------------------------------------end private variable
- //------------------------------------begin public method
- this.Go = fGo;
- //------------------------------------end public method
- //------------------------------------begin private method
- function fAddElement
- (sId, sOriginColor, sOverColor, sOutColor, iTime, iIntervalMs, bCompColor, sClassName, sOverClassName)
- {
- var Obj = null;
- if(typeof(sId)=="string")
- {
- Obj = document.getElementById(sId);
- }
- else if(typeof(sId)=="object")
- {
- Obj = sId;
- }
- if(!Obj||Obj==null)
- {
- alert("对象不能为空!");
- return;
- }
- if(!bCompColor) bCompColor = false;
- else bCompColor = true;
- if(!sClassName) sClassName = "";
- if(!sOverClassName) sOverClassName = "";
- if(!sOriginColor) sOriginColor = "#ffffff";
- if(!sOverColor) sOverColor = "#cccccc";
- if(!sOutColor) sOutColor = sOriginColor;
- if(!iTime) iTime = 10;
- if(!iIntervalMs) iIntervalMs = 50;
- Obj["Extend"] = {};
- Obj["Extend"]["OriginalColor"] = sOriginColor;
- Obj["Extend"]["MoveColor"] = sOverColor;
- Obj["Extend"]["OutColor"] = sOutColor;
- Obj["Extend"]["Time"] = iTime;
- Obj["Extend"]["IntervalMs"] = iIntervalMs;
- Obj["Extend"]["CompColor"] = bCompColor;
- Obj["Extend"]["ClassName"] = sClassName;
- Obj["Extend"]["OverClassName"] = sOverClassName;
- var iPos = Tl.Element.Set.length;
- Tl.Element.Set[iPos] = Obj;
- } // end function fAddElement
- function fGo()
- {
- for(var i = 0, j=Tl.Element.Set.length; i<j; i++)
- {
- var TempObj = Tl.Element.Set[i];
- TempObj.style.backgroundColor = TempObj["Extend"]["OriginalColor"];
- TempObj["Interval"] = {}
- if(TempObj["Extend"]["CompColor"])
- {
- TempObj.style.color = fGetCompColor(TempObj["Extend"]["OriginalColor"]);
- }
- if(TempObj["Extend"]["ClassName"]!="")
- {
- TempObj.className = TempObj["Extend"]["ClassName"];
- }
- TempObj.onmouseover =
- function()
- {
- try
- {
- clearInterval(this["Interval"]["Out"]["Go"]);
- }
- catch(e)
- {
- }
- this["Interval"]["Over"] ={}
- this["Interval"]["Over"]["Count"] = 0;
- if(this["Extend"]["OverClassName"]!="")
- {
- this.className = this["Extend"]["OverClassName"];
- }
- var BgColor = this.style.backgroundColor==""?"#ffffff":this.style.backgroundColor;
- if(/rgb/(/i.test(BgColor))
- {
- BgColor = fRgbToHex(BgColor);
- }
- //function fGetCompColor(sInput, sOpt, bNoSharp, bDebug)
- this["Interval"]["Over"]["FadeArray"] =
- fFade
- (
- BgColor,
- this["Extend"]["MoveColor"],
- this["Extend"]["Time"],
- false,
- true
- );
- var me = this;
- this["Interval"]["Over"]["Go"] =
- setInterval
- (
- function()
- {
- if(me["Interval"]["Over"]["Count"]>=me["Interval"]["Over"]["FadeArray"].length)
- {
- clearInterval(me["Interval"]["Over"]["Go"]);
- me["Interval"]["Over"]["Count"] = null;
- return;
- }
- var sBgColor = me["Interval"]["Over"]["FadeArray"][me["Interval"]["Over"]["Count"]];
- me.style.backgroundColor = sBgColor;
- if(me["Extend"]["CompColor"])
- {
- me.style.color = fGetCompColor(sBgColor);
- }
- if(Tl.Debug)
- defaultStatus = me["Interval"]["Over"]["Count"];
- me["Interval"]["Over"]["Count"]++;
- }
- ,
- me["Extend"]["IntervalMs"]
- ) // end setInterval
- } // end TempObj.onmouseover
- TempObj.onmouseout =
- function()
- {
- try
- {
- clearInterval(this["Interval"]["Over"]["Go"]);
- }
- catch(e)
- {
- }
- this["Interval"]["Out"] ={}
- this["Interval"]["Out"]["Count"] = 0;
- if(this["Extend"]["ClassName"]!="")
- {
- this.className = this["Extend"]["ClassName"];
- }
- var BgColor = this.style.backgroundColor==""?"#ffffff":this.style.backgroundColor;
- if(/rgb/(/i.test(BgColor))
- {
- BgColor = fRgbToHex(BgColor);
- }
- this["Interval"]["Out"]["FadeArray"] =
- fFade
- (
- BgColor,
- this["Extend"]["OutColor"],
- this["Extend"]["Time"],
- false,
- true
- );
- var me = this;
- this["Interval"]["Out"]["Go"] =
- setInterval
- (
- function()
- {
- if(me["Interval"]["Out"]["Count"]>=me["Interval"]["Out"]["FadeArray"].length)
- {
- clearInterval(me["Interval"]["Out"]["Go"]);
- me["Interval"]["Out"]["Count"] = null;
- return;
- }
- var sBgColor = me["Interval"]["Out"]["FadeArray"][me["Interval"]["Out"]["Count"]];
- me.style.backgroundColor = sBgColor;
- if(me["Extend"]["CompColor"])
- {
- me.style.color = fGetCompColor(sBgColor);
- }
- if(Tl.Debug)
- defaultStatus = me["Interval"]["Out"]["Count"];
- me["Interval"]["Out"]["Count"]++;
- }
- ,
- me["Extend"]["IntervalMs"]
- ) // end setInterval
- } // end TempObj.onmouseover
- } // end for
- } // end function fGo
- function fFade(sOriginalColor, sFinalColor, iTime, sOpt/*positive|negative|auto*/, bPadSharp)
- {// shawl.qiu script : return Array
- if(!sOriginalColor||sOriginalColor=="")
- {
- alert("原色不能为空!");
- return;
- }
- if(!sFinalColor||sFinalColor=="")
- {
- alert("最终色不能为空!");
- return;
- }
- if(!iTime||typeof(iTime)!="number") iTime = 5;
- if(!sOpt) sOpt = "auto";
- var sSharp = "";
- if(bPadSharp) sSharp = "#";
- var Debug = false;
- var oAr = fSplitColor(sOriginalColor);
- var oArInt = fHexArrayToInt(oAr);
- var fAr = fSplitColor(sFinalColor);
- var fArInt = fHexArrayToInt(fAr);
- var ReturnAr = [];
- switch(sOpt)
- {
- default:
- var SubtractAr = [];
- var SpanAr = [];
- var ReturnArInt = [];
- for(var i=0, j=oArInt.length; i<j; i++)
- {
- SubtractAr[i] = fArInt[i] - oArInt[i];
- SpanAr[i] = SubtractAr[i]/iTime;
- }
- for(var i=0, j=iTime; i<j; i++)
- {
- ReturnArInt[i] = [];
- ReturnArInt[i][0] = parseInt(oArInt[0]+(SpanAr[0]*(i+1)));
- ReturnArInt[i][1] = parseInt(oArInt[1]+(SpanAr[1]*(i+1)));
- ReturnArInt[i][2] = parseInt(oArInt[2]+(SpanAr[2]*(i+1)));
- ReturnAr[i] = ""
- +sSharp
- +fPadStr(ReturnArInt[i][0].toString(16)).toUpperCase()
- +fPadStr(ReturnArInt[i][1].toString(16)).toUpperCase()
- +fPadStr(ReturnArInt[i][2].toString(16)).toUpperCase()
- ;
- }
- sFinalColor= sFinalColor.replace(/^/#/, "");
- if(bPadSharp) sFinalColor = "#"+sFinalColor;
- ReturnAr[ReturnAr.length-1] = sFinalColor.toUpperCase();
- break;
- }
- if(Debug)
- {
- alert
- (
- " oAr: "+oAr
- +"/n oArInt: "+oArInt
- +"/n fAr: "+fAr
- +"/n fArInt: "+fArInt
- +"/n typeof(sOpt): "+typeof(sOpt)
- +"/n SubtractAr: "+SubtractAr
- +"/n SpanAr: "+SpanAr
- +"/n ReturnArInt: "+ReturnArInt
- +"/n ReturnAr: "+ReturnAr
- );
- } // end if
- return ReturnAr.slice();
- } // end function fFade
- function fPadStr(sSrc, sPad, nLen)
- {// shawl.qiu script
- if(!sSrc)return false;
- if(!sPad)sPad='0';
- if(!nLen)nLen=2;
- sSrc+='';
- if(sSrc.length>=nLen)return sSrc;
- sPad=new Array(nLen+1).join(sPad);
- var re=new RegExp('.*(.{'+(nLen)+'})$');
- return (sPad+sSrc).replace(re,'$1');
- } // end function fPadStr
- function fHexArrayToInt(ar)
- { // shawl.qiu script : return array
- var TempAr = [];
- for(var i=0, j=ar.length; i<j; i++)
- {
- TempAr[i] = parseInt(ar[i], 16);
- }
- return TempAr.slice();
- } // end function fHexArrayToInt
- function fSplitColor(sColor)
- { // shawl.qiu script : return array
- if(!sColor||sColor=="")
- {
- alert("颜色不能为空!");
- return;
- }
- var Debug = true;
- sColor = sColor.replace(/^/#/, "");
- if(sColor.length == 3)
- {
- var sTemp = "";
- for(var i = 0, j=sColor.length; i<j; i++)
- {
- sTemp+= ""+sColor.charAt(i)+sColor.charAt(i);
- }
- sColor = sTemp;
- }
- if(sColor.length!=6)
- {
- alert("无法识别的颜色代码!")
- return;
- }
- var arHex = [];
- arHex[0] = ""+sColor.charAt(0)+sColor.charAt(1);
- arHex[1] = ""+sColor.charAt(2)+sColor.charAt(3);
- arHex[2] = ""+sColor.charAt(4)+sColor.charAt(5);
- return arHex.slice();
- } // end function fSplitColor
- function fGetCompColor(sInput, sOpt, bNoSharp, bDebug)
- {// shawl.qiu script : return string
- if(!sInput) sInput = "#000000";
- if(!sOpt) sOpt = 'hex';
- sOpt = sOpt.toLowerCase();
- var arCell = [];
- var arHex = [];
- var arHexFinal = [];
- var arInt = [];
- var arIntFinal = [];
- var Debug = bDebug;
- if(Debug)
- {
- alert
- (
- "sInput: "+sInput
- +" sOpt: "+sOpt
- );
- }
- sInput = sInput.replace(/^/#/, "");
- switch(sOpt)
- {
- case "rgb":
- break;
- default:
- if(sInput.length==3)
- {
- var arTemp = fStringToArray(sInput);
- sInput = ""+arTemp[0]+arTemp[0]+arTemp[1]+arTemp[1]+arTemp[2]+arTemp[2];
- }
- if(sInput.length==6)
- {
- arCell = fStringToArray(sInput);
- arHex[0] = "0x"+arCell[0]+arCell[1];
- arHex[1] = "0x"+arCell[2]+arCell[3];
- arHex[2] = "0x"+arCell[4]+arCell[5];
- arInt[0] = parseInt(arHex[0], 16);
- arInt[1] = parseInt(arHex[1], 16);
- arInt[2] = parseInt(arHex[2], 16);
- arIntFinal[0] = Math.abs(255-arInt[0]);
- arIntFinal[1] = Math.abs(255-arInt[1]);
- arIntFinal[2] = Math.abs(255-arInt[2]);
- arHexFinal[0] = fPadStr(arIntFinal[0].toString(16)).toUpperCase();
- arHexFinal[1] = fPadStr(arIntFinal[1].toString(16)).toUpperCase();
- arHexFinal[2] = fPadStr(arIntFinal[2].toString(16)).toUpperCase();
- if(Debug)
- {
- alert("arCell: "+arCell);
- alert("arHex: "+arHex);
- alert("arInt: "+arInt);
- alert("arIntFinal: "+arIntFinal);
- alert("arHexFinal: "+arHexFinal);
- }
- if(bNoSharp) return arHexFinal.join("");
- return "#"+arHexFinal.join("");
- }
- else
- {
- alert("无法识别的十六进制颜色代码!");
- }
- break;
- }
- return "000000";
- function fStringToArray(sInput)
- {// shawl.qiu script
- var arCell = [];
- var iCount = 0;
- var iLen = sInput.length;
- while(iCount<iLen)
- {
- arCell[iCount] = sInput.charAt(iCount);
- iCount++;
- }
- return arCell;
- } // end function fStringToArray
- function fPadStr(sSrc, sPad, nLen)
- {// shawl.qiu script
- if(!sSrc)return false;
- if(!sPad)sPad='0';
- if(!nLen)nLen=2;
- sSrc+='';
- if(sSrc.length>=nLen)return sSrc;
- sPad=new Array(nLen+1).join(sPad);
- var re=new RegExp('.*(.{'+(nLen)+'})$');
- return (sPad+sSrc).replace(re,'$1');
- } // end function fPadStr
- } // end function fGetCompColor
- function fRgbToHex(sRgb, bNoSharp, bDebug)
- { // shawl.qiu script
- if(!sRgb||sRgb=="")
- {
- alert("RGB颜色代码不正确!");
- return;
- }
- var Debug = bDebug;
- var sSharp = "";
- if(!bNoSharp) sSharp = "#";
- if(/rgb/(/i.test(sRgb))
- {
- sRgb = sRgb.replace(/^[/s/S]*?rgb/((.*?)/)[/s/S]*/gi, "$1").replace(//s+/g, "");
- }
- var RgbAr = sRgb.split(",");
- var sReturn = "";
- sReturn =
- sSharp
- +(fPadStr((RgbAr[0]-0).toString(16)).toUpperCase())
- +(fPadStr((RgbAr[1]-0).toString(16)).toUpperCase())
- +(fPadStr((RgbAr[2]-0).toString(16)).toUpperCase())
- ;
- if(Debug)
- {
- alert(sReturn);
- }
- return sReturn;
- function fPadStr(sSrc, sPad, nLen)
- {// shawl.qiu script
- if(!sSrc)return false;
- if(!sPad)sPad='0';
- if(!nLen)nLen=2;
- sSrc+='';
- if(sSrc.length>=nLen)return sSrc;
- sPad=new Array(nLen+1).join(sPad);
- var re=new RegExp('.*(.{'+(nLen)+'})$');
- return (sPad+sSrc).replace(re,'$1');
- } // end function fPadStr
- } // end function fRgbToHex
- //------------------------------------end private method
- } // shawl.qiu code
- //---------------------------------end class Faded()---------------------------------//