javascript文字特效

1、简单的文字变色

-------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<title>简单文字变色</title>
</head>


<body>

<script language ="javascript">
    var colors = new Array("red","blue","brown","yellow","pink","purple");
    var i = 0; 
    function changeFgcolor() {
        document.fgColor = colors[i++];
         if(i == colors.length) {
            i = 0;//这里最开始多写了一个等号,以致不能实现文字颜色的循环变换,记住教训啊!
        }
    }
    setInterval("changeFgcolor()",500);
    window.onload = changeFgcolor;
</script>

<h1>
    简单的文字变色实例
</h1>
</body>

</html>

------------------------------

2、文字变色

------------------------------

<html>

<head>

<title></title>
<script language="javascript">
    var colors = new Array("red","blue","brown","yellow","pink","purple","cc3300","cc00aa","66ffcc");
    var a = 0; 
    var b = 1;
    function changeColor() {
        color = colors[a];
        var str = "<font size = '8' face = '黑体' color = ' " + color + " '><p>javascript中实现文字的颜色变换</p></font>";
        document.all.div1.innerHTML = str;
        
        //实现颜色循环
        a += b;
        if(a > colors.length || a < 0) {//当a小于颜色数组中的第一个元素的索引或大于最后一个元素的索引时,改变b的符号。
            b = -b;
        }
        
        var xx = setTimeout("changeColor()",300);
    }
</script>
</head>

<body onload = "changeColor()">
<div id="div1" align="center"></div>
</div>
</body>

</html>
---------------------------------

3、变换的文字

----------------------------------------------------

<html>
<head>
<title>变换的文字</title>
</head>

<body >
<div id="cc" align="center" style="position: absolute; left: -1; top: 5; width: 1003px; height: 19"></div>
<script language="javascript">
    var words = new Array();
    var colors = new Array("red","blue","brown","pink","purple");
    words[0] = "aaaaaaaaaaaaaaa";
    words[1] = "bbbbbbbbbbbbbbb";
    words[2] = "ccccccccccccccc";
    words[3] = "ddddddddddddddd";
    words[4] = "eeeeeeeeeeeeeee";    
    
    var i = 0; 
   document.all.cc.style.width=document.body.clientWidth;//将层的宽度设为页面工作区的宽度
    
    //自定义函数changeWords(),用于改变层的文字用字体颜色
    function changeWords() {
        if(i == words.length) {
            i = 0; 
        }        //这里开始又多写一个等号!!致使程序怎么都不对!
            //动态替换文字及颜色
      // cc.innerHTML = '<font color = "' + colors[i++] +'", size = "5">' +words[i++]+'</font>';
      //注意 !不能像上面这样写!!这样的话每次输出文字时i是自加了两次!!
        cc.innerHTML = '<font color = "' + colors[i] +'", size = "10'">' +words[i]+'</font>';
        i++;
        //
        setTimeout("changeWords()",500);
    }
    changeWords();
    
</script>
</body>

</html>
-----------------------------------------------

4、追逐点亮的文字(霓虹灯效果)

<html>

<head>

<title>追逐点亮的文字</title>


<script type="text/javascript">
    var str = "欢迎光临控制后台";
    var sLen = str.length;
    /*
    var ss = str.substring(0,1);//测试下这样截的是几个字符,结果是1,ss的值是‘欢’
    alert(ss);
    alert(ss.length);
    */
    var i = 0;
    function gogo() {
        i++;//i必须在些方法外定义,因为这个函数要被循环调用,而每次调用都要求i的值和上一次不同,所以i不能在些方法内定义。
        i = (i >= sLen)?0:i;
        i = (i < 0)?(sLen-1):i;
        a.innerHTML = str.substring(0,i) + "<font color = '#00FF33'>" + str.substring(i,i+1) +"</font>" + str.substring(i+1,sLen);
    }
    setInterval("gogo()",400);

</script>
</head>

<body>
<div id="a" style="font-size: 40px; color: #78a392"></div>
</body>

</html>
--------------------------

5、萤光文字

-------------------

<html>

<head>

<title></title>

</head>

<body>
<script language="javascript">
    var str = "明日科技图书";
    var divLay = '<div id = "div1" align = "center" style = "width:400px; filter:glow(#cc0022,strength=2); font-size:40px; font-family:Courier New;">'+str+"</div>";
    document.write(divLay);
    
    function change() {
        if(div1.filters.glow.strength == 2) {
            div1.filters.glow.color = "#29e9e6";//设置层中字体的外边框的颜色
            div1.filters.glow.strength = 4;//设置层中字体的外边框的长度
        }
        else {
            div1.filters.glow.color = "#cc0033";
            div1.filters.glow.strength = 2;
        }
    }
    setInterval("change()",200);
</script>
</body>

</html>

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值