JS如何控制多文字闪动效果?

JavaScript012

JS如何控制多文字闪动效果?,第1张

把两段JS脚本合为一个:

<script language="JavaScript" type="text/javascript">

if (navigator.appName.indexOf('Netscape') == '-1')

{

var colors = ["#000000","#FF5500","#000000","#FF5500","#000000","#FF5500"]

var nextcolor = 0

var nextcolor1 = 1

function changecolor()

{

document.all.FlashText1.style.color = colors[nextcolor++]

document.all.FlashText2.style.color = colors[nextcolor1++]

nextcolor = nextcolor % colors.length

nextcolor1 = nextcolor1 % colors.length

}

setInterval("changecolor()", 200)

}

</script>

网页元素一个一个删除,然后一个一个载入新网页的元素,这样子网页在过度过程中会出现变形和抖动。

比较好的办法是把老网页和新网页的元素分别放置到一个层里,开始是现实老网页层,新网页层display设为none,不显示。

过度时使用新网页层盖住老网页层,过度效果就是新网页层盖住老网页层的过程效果。效果可以百度一下。当新网页层完全盖住老网页层时,把老网页层(这是页个元素)删除就可以了。

<html><head>

<title>打字效果的文字特效</title>

<script language="JavaScript">

var layers = document.layers

var style = document.all

var both = layers || style

var idme = 908601

if(layers) //如果不是ie浏览器

{

layerRef = 'document.layers'

styleRef = ''

}

if(style) //如果是ie浏览器

{

layerRef = 'document.all'

styleRef = '.style'

}

function writeOnText(obj, str) { //函数在页面上打印字符串

if(layers) {

with(document[obj]) {

document.open()

document.write(str)//write方法打印字符串

document.close()

}

}

if(style) eval(obj+'.innerHTML = str')//使用innerHTML属性显示字符串

}

var dispStr = new Array("javascript源码大全")//字符串数组

var overMe = 0

function txtTyper(str, idx, idObj, spObj, clr1,clr2, delay, plysnd) //函数:实现打字效果

{

var tmp0 = tmp1 = '', skip = 100

if(both &&idx <= str.length) {

if(str.charAt(idx) == '<') {

while(str.charAt(idx) != '>') idx++

idx++

}

if(str.charAt(idx) == '&' &&str.charAt(idx+1) != '') {

while(str.charAt(idx) != '') idx++

idx++

}

tmp0 = str.slice(0, idx)

tmp1 = str.charAt(idx++)

if(overMe==0 &&plysnd==1) {

if(navigator.plugins[0]) {

if(navigator.plugins["LiveAudio"][0].type == "audio/basic" &&navigator.javaEnabled()) {

document.embeds[0].stop()

setTimeout("document.embeds[0].play(false)", 100)

}

} else if(document.all) {

ding.Stop()

setTimeout("ding.Run()", 100)

}

overMe = 1

} else {

overMe = 0

}

writeOnText(idObj, "<span class="+spObj+"><font color='"+clr1+"'>"+tmp0+"</font><font color='"+clr2+"'>"+tmp1+"</font></span>")

//调用writeOnText函数将字符显示在网页上

setTimeout("txtTyper('"+str+"', "+idx+", '"+idObj+"', '"+spObj+"', '"+clr1+"', '"+clr2+"', "+delay+", "+plysnd+")", delay)

}

}

function init()

{

txtTyper(dispStr[0], 0, 'tt10', 'ttll', '#339933', '#99FF33', 300, 0) //调用txtTyper函数开始打字

}

</script>

</head>

<body onLoad="init()">

<center>

<h1>打字效果的文字特效</h1>

<hr />

<div class="ttll" id="tt10"></div>

</center>

</body>

</html>

用IE 打开 试过了。。。