多國語言翻譯:

展開 | 闔起

人氣:3463
b168168tw - javaScript | 2013-02-08 | 人氣:3463

javaScript製作彩色文字的方法!
可以用於Xoops佈景的標題文字特效製作,讓原本單色的文字顯示多種隨機的色彩。


1、將以下code複製起來,貼到<HEAD> 裡面 </HEAD>
 

 <script language="JavaScript">
 
 
 hexa = new MakeArray(16)
 hexa[10] = "A"
 hexa[11] = "B"
 hexa[12] = "C"
 hexa[13] = "D"
 hexa[14] = "E"
 hexa[15] = "F"  
 
 function MakeArray(n)
 {
 this.length = n
 for (var i = 0; i <= n; i++)
 this[i] = i
 return this
 }
 
 function colours(text){
 
 var posa = 0
 var posb = 1
 while (posa <= text.length){
 var r = Math.floor(Math.random() * 15)
 var rr= Math.floor(Math.random() * 15)
 var g = Math.floor(Math.random() * 15)
 var gg = Math.floor(Math.random() * 15)
 var b = Math.floor(Math.random() * 15)
 var bb = Math.floor(Math.random() * 15)
 if (text.substring(posa,posb) == "<"){
 var posaa = 0
 posaa = posa
 while (text.substring(posaa,posb) != ">"){
 posaa++
 posb++
 }
 document.write(text.substring(posa, posb))
 posa = posb 
 posb = posa + 1
 }
 document.write("<font color=#"+hexa[r]+hexa[rr]+hexa[g]+hexa[gg]+hexa[b]+hexa[bb]+">")
 document.write(text.substring(posa, posb)+"</font>")
 posa++
 posb++
 }
 }
 
 </script>

 

2、將以下的code複製起來,貼到<body> 裡面裡面 </body>

 <script language = "javascript"> 
 text = "文字文字文字文字文字文字文字"
 colours(text)
 </script>  

 

3、如果要用於Xoops佈景,可以將文字文字替換為Xoops的Smarty標籤。
 

 <script language = "javascript"> 
 text = "<{$block.title}>"
 colours(text)
 </script>  

4、存檔,完成js彩色字特效的套用工作。

教學撰寫:徐嘉裕Neil hsu

neilthemesSimple網站設計開發:Neil網站設計工坊,徐嘉裕Neilhsu
Website CMS by:XOOPS 網站設計:Neil網站設計工坊
營業人名稱:尼爾網站設計工坊 統一編號:37586308
服務專線:0931229118網路電話:07010003568
Do NOT follow this link or you will be banned from the site!