js 文字逐个闪烁

js 文字逐个闪烁,第1张

function changeCharColor() {

    //第五行

    Text.charAt(i) //改成 text.charAt(i)

其实 navigator.appName == "Netscape" 这个判断大可不必

仅使用以下代码,各主流浏览器均可支持

text = "欢迎光临网页制作特效站"

color1 = "blue"

color2 = "red"

fontsize = "6"

speed = 100

i = 0

document.write("<div id=a></div>")

function changeCharColor() {

    str = "<center><font face=arial size=" + fontsize + "><font color=" + color1 + ">"

    for (var j = 0 j < text.length j++) {

        if (j == i) {

            str += "<font face=arial color=" + color2 + ">" + text.charAt(i) + "</font>"

        } else {

            str += text.charAt(j)

        }

    }

    str += "</font></font></center>"

    a.innerHTML = str

    (i == text.length) ? i = 0 : i++

}

setInterval("changeCharColor()", speed)

以改变字体颜色为例

js部分

// 页面加载完毕要执行的 *** 作放到这个函数

window.onload=function (){

// 使用js实现

document.getElementById('wenzi').style.color="red"

// 使用jqeury实现

$('#wenzi2').css('color','yellow')

}

html部分

<span id="wenzi">js动态添加文字样式示例</span>

<span id="wenzi2">js动态添加文字样式示例2</span>

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


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11898014.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-19
下一篇2023-05-19

发表评论

登录后才能评论

评论列表(0条)

    保存