精彩的变色文字特效

本文介绍了一种使用JavaScript实现的特殊文本显示效果,能够使文本中的每个字符以不同的随机颜色呈现,同时支持HTML标签的正常显示。此效果通过自定义函数随机生成十六进制颜色值来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script language="JavaScript">
 
 
 /* This script was made by Erik.  You can contact him me worfy@geocities.com or at my homepage www.geocities.com/Area51/Corridor/4090. I know that it doesn't look pretty in the source code, but that couldn't be helped.  Feel free to modify this script in any way but please give me credit.  This is my first real script. 
 BTW  for you yankees, I spell colour with the U because I'm Canadain.*/
 
 
 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>
 
   <script language = "javascript">
 
 text = "This JavaScript shows every other letter of text as a different, random colour."
 text +="You can also use any <blink> <font size=9> HTML </font> </blink> codes that you want"
 text +=" As long as you don't use quotation marks and the commands have a space between them."
 text +="  You can use any background colour or picture that you want, but black or white is sugeste"
 text +="d <b> <u>HAVE FUN!!! </u> </b>"
 
 colours(text)
 
 </script>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值