javasript代码
<divid="blink">闪烁的文字</div>
<scriptlanguage="javascript">
functionchangeColor(){
varcolor="#f00|#0f0|#00f|#880|#808|#088|yellow|green|blue|gray"
color=color.split("|")
document.getElementById("blink").style.color=color[parseInt(Math.random()*color.length)]
}
setInterval("changeColor()",200)
</script>
css代码就是文字闪烁text-decoration:blink不过很可惜,IE、Chrome或Safari不支持"blink"属性值,所以只有在Firefox和Opera下支持这CSS实现在闪动效果。加上js代码就可以了。
<PUBLIC:COMPONENT URN="rainbow" name="darainbow()"/><PUBLIC:ATTACH EVENT = "oncontentready" ONEVENT ="beginIt()"/>
<SCRIPT language="JAVASCRIPT">
var Kill_ID=null
var internalValue
var originalValue
function putValue(){
element.innerHTML=internalValue
encapsulate()
startSwirl()
}
function eventHandler(){
clearInterval(Kill_ID)
internalValue=element.value
element.detachEvent("onpropertychange",eventHandler)
if(event.propertyName=="value"){
element.innerHTML=internalValue
putValue()
} else startSwirl()
element.attachEvent("onpropertychange",eventHandler)
}
function swirl(){
var I
I=ran(internalValue.length-1,0)
if(element.children(I) != null)element.children(I).style.color=randomColor()
}
function startSwirl(){
if (element.swirlInterval == null)
element.swirlInterval=50
if ((internalValue!=null) &&(element.swirlInterval!=0))
Kill_ID=setInterval(swirl,element.swirlInterval)
}
function encapsulate(){
var I
var tempStr=""
for (I=0I <internalValue.lengthI++){
tempStr += "<SPAN style=\"color:"+randomColor()+"\">" + internalValue.substr(I,1) + "</SPAN>"
}
innerHTML=tempStr
}
function ran(upperbound, lowerbound){
return(parseInt((upperbound - lowerbound + 1) * Math.random() + lowerbound))
}
function randomColor(){
var R=ran(255,0)
var G=ran(255,0)
var B=ran(255,0)
R=R.toString(16)
G=G.toString(16)
B=B.toString(16)
if (R.length==1)R="0"+R
if (G.length==1)G="0"+G
if (B.length==1)B="0"+B
return("#"+R+G+B)
}
function beginIt(){
internalValue=element.value
originalValue=element.innerHTML
if (internalValue==null)
internalValue=element.innerHTML
putValue()
element.attachEvent("onpropertychange",eventHandler)
}
function clearIt(){
clearInterval(Kill_ID)
element.detachEvent("onpropertychange",eventHandler)
element.innerHTML=originalValue
}
</script>
<div id="blink"><font face="Arial"><b>祝大家新年快乐!</b></font></div><script language="javascript">
function changeColor(){
var color="#f00|#0f0|#00f|#880|#808|#088|yellow|green|blue|gray"
color=color.split("|")
document.getElementById("blink").style.color=color[parseInt(Math.random() * color.length)]
}
setInterval("changeColor()",200)
</script>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)