好消息是我这里直接报错  根本不能运行  从你代码上看貌似都走的ie标准  没做w3c的方法啊

解决方案 »

  1.   

    本帖最后由 net_lover 于 2014-03-30 14:33:05 编辑
      

  2.   

    根据你的效果,写了个类似的基于面向对象的,如下<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style>
    body{background:#5498E1; height:2000px;}
    .box {color:#0066ff; font-family: 宋体; font-size: 20pt; font-weight: normal;position: absolute;top: 0px;}
    </style>
    <script>
    //function Font(message,separator,warpTag)
    function Font(config)
    {
    this.message=config.message;
    this.separator=config.separator||'  ';//默认分隔符号连个空格
    this.warpTag=config.warpTag||'div';//默认外层包裹标签为div
    this.warpClass=config.warpClass;
    this.speed=config.speed||30;//交替速度,以毫秒为单位,默认30毫秒
    }
    Font.prototype.init=function()//初始化操作
    {
    this.createElement();//开始创建元素
    this.shakeFont();//加颜色
    }
    Font.prototype.createElement=function()
    {
    this.fontSpanArr=[];
    var fontArr=this.message.split(/\s+/);
    var oSpan=null;
    this.oWarp=document.createElement(this.warpTag);
    this.oWarp.className=this.warpClass;
    var oSeparator=document.createElement('span');
    oSeparator.innerHTML=this.separator;
    var oFrag=document.createDocumentFragment();
    for(var i=0;i<fontArr.length;i++)
    {
    oSpan=document.createElement('span');
    oSpan.innerHTML=fontArr[i];
    oFrag.appendChild(oSpan);
    oFrag.appendChild(oSeparator);
    this.fontSpanArr.push(oSpan);
    }
    this.oWarp.appendChild(oFrag);
    document.body.appendChild(this.oWarp);
    }
    Font.prototype.shakeFont=function()
    {
    for(var i=0;i<this.fontSpanArr.length;i++)
    {
    clearInterval(this.fontSpanArr[i].timer);
    (function(obj,j){
    obj.fontSpanArr[j].timer=setInterval(function(){
    obj.fontSpanArr[j].style.color=obj.getRanColor();
    },30);})(this,i);

    }
    }
    Font.prototype.getRanColor=function()
    {
    return '#'+('00000'+(Math.random()*0x1000000<<0).toString(16)).slice(-6);
    }
    window.onload=function()
    {
    var obj=new Font({message:'祝  你  天  天  好  心  情',warpClass:'box'});
    obj.init();
    document.onmousemove=function(ev){
    var ev=ev||event;
    obj.oWarp.style.left=ev.clientX+10+'px';
    obj.oWarp.style.top=ev.clientY+10+(document.body.scrollTop||document.documentElement.scrollTop)+'px';
    }
    }
    </script>
    </head><body>
    </body>
    </html>