html中逐字显示字怎么写代码?举个简单的例子。

html-css035

html中逐字显示字怎么写代码?举个简单的例子。,第1张

第一步:请修改<BODY>:

<BODY onload=init()>

第二步:将以下代码加入HEML的<BODY></BODY>之间

<script language=javascript>

var layers =document.layers,style=document.all,both=layers||style,idme=908601

if(layers){layerRef='document.layers'styleRef =''}if(style){layerRef='document.all'styleRef = <br/>'.style'}

function writeOnText(obj,str){

if(layers)with(document[obj]){ document.open()document.write(str)document.close()}

if(style)eval(obj+'.innerHTML=str')}

var dispStr=new Array("打字效果代码")//这里面的就是内容文字

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<br/>[0].stop()<br/>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>")

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

function init(){txtTyper(dispStr[0], 0, 'ttl0', 'ttl1', '#339933', '#99FF33', 300, 0)}

</script>

<DIV class=ttl1 id=ttl0></DIV>

<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 打开 试过了。。。