这段js在火狐下怎么不行啊
function moveAlong(layerName, paceLeft, paceTop, fromLeft, fromTop)
{
clearTimeout(eval(layerName).timer)
if(eval(layerName).curLeft != fromLeft)
{
if((Math.max(eval(layerName).curLeft, fromLeft) - Math.min(eval(layerName).curLeft, fromLeft)) < paceLeft){eval(layerName).curLeft = fromLeft}
else if(eval(layerName).curLeft < fromLeft){eval(layerName).curLeft = eval(layerName).curLeft + paceLeft}
else if(eval(layerName).curLeft > fromLeft){eval(layerName).curLeft = eval(layerName).curLeft - paceLeft}
if(ie){document.all[layerName].style.left = eval(layerName).curLeft}
if(ns){document.master[layerName].left = eval(layerName).curLeft}
}
if(eval(layerName).curTop != fromTop)
{
  if((Math.max(eval(layerName).curTop, fromTop) - Math.min(eval(layerName).curTop, fromTop)) < paceTop)
  {eval(layerName).curTop = fromTop}
else if(eval(layerName).curTop < fromTop){eval(layerName).curTop = eval(layerName).curTop + paceTop}
else if(eval(layerName).curTop > fromTop){eval(layerName).curTop = eval(layerName).curTop - paceTop}
if(ie){document.all[layerName].style.top = eval(layerName).curTop}
if(ns){document.master[layerName].top = eval(layerName).curTop}
}
eval(layerName).timer=setTimeout('moveAlong("'+layerName+'",'+paceLeft+','+paceTop+','+fromLeft+','+fromTop+')',30)
}function setPace(layerName, fromLeft, fromTop, motionSpeed)
{
eval(layerName).gapLeft = (Math.max(eval(layerName).curLeft, fromLeft) - Math.min(eval(layerName).curLeft, fromLeft))/motionSpeed
eval(layerName).gapTop = (Math.max(eval(layerName).curTop, fromTop) - Math.min(eval(layerName).curTop, fromTop))/motionSpeed
moveAlong(layerName, eval(layerName).gapLeft, eval(layerName).gapTop, fromLeft, fromTop)
}
function FixY()
{
if(document.body.scrollTop>0){
if(ie){sidemenu.style.top = document.body.scrollTop+90}
}
else
{
if(ie){sidemenu.style.top = document.documentElement.scrollTop+90}

if(ns){sidemenu.top = window.pageYOffset+90}

 
 
js调用
<script language="javascript">
  
window.onerror = function(){}
var expandState = 0;function expand(){ if(expandState == 0){setPace('master', 0, 10, 10); if(ie){document.menutop.src = 'Images/menui.jpg'}; expandState = 1;}
else{setPace('master', -196, 10, 10); if(ie){document.menutop.src='Images/menuo.jpg'}; expandState = 0;}
}
document.write("<style type=text/css>#master {LEFT: -196px; POSITION: absolute; TOP: 90px; VISIBILITY: visible; Z-INDEX: 999}</style>")
document.write("<table id=master width='218' border='0' cellspacing='0' cellpadding='0'><tr><td></td><td rowspan='2' valign='top'><img id=menu onMouseOver=javascript:expand() border=0 height=100 name=menutop src=Images/menuo.jpg width=30></td></tr>");
document.write("<tr><td valign='top'><table width='101%' border='0' cellpadding='0'><tr><td height='400' valign='top'><table width=100% height='100%' border=0 cellpadding=0 cellspacing=5 bordercolor='#666666' bgcolor=#006699 style=FILTER: alpha(opacity=90)><tr>");
document.write("<td align='center' bordercolor='#ecf6f5'><font color=FFFFFF>ONLINE SERVICES<br><font size=+0.5><strong>在线服务中心</strong></font></font></td></tr><tr><td valign='top' bordercolor='#ecf6f5' align='center'>");
document.write("<iframe width='100%' marginwidth='0' marginheight='0' height='350' src='http://"+window.location.host+"/kfu.html' frameborder=0 allowTransparency='true'></iframe></td></tr></table></td></tr></table></td></tr></table>");
var ie = document.all ? 1 : 0
var ns = document.layers ? 1 : 0
var master = new Object('element')
master.curLeft = -200; master.curTop = 10;
master.gapLeft = 0; master.gapTop = 0;
master.timer = null;
if(ie){var sidemenu = document.all.master;}
if(ns){var sidemenu = document.master;}
setInterval('FixY()',100);
    
    
</script>

解决方案 »

  1.   

    楼主非要这个效果啊?我上次看过,要改,还不如重新写!
    他不但js 不兼容,还css 都不兼容ff!
      

  2.   

    ff不认识eval(id),要用document.getElementById(id)来取对象
      

  3.   

    不知道楼主在哪找的代码?不兼容的地方太多。完全没改的欲望!看着头痛!
    var ie = document.all ? 1 : 0
    var ns = document.layers ? 1 : 0 浏览器判断方式// 局部变量完全无意义
    if(ie){var sidemenu = document.all.master;}
    if(ns){var sidemenu = document.master;}
    eval(layerName).curLeft ,就算用document.getElementById(id)来取对象
    这个对象拿来的属性 curLeft !
    你的curLeft  是赋值给var master = new Object('element')
    master.curLeft = -200; master.curTop = 10;
    master.gapLeft = 0; master.gapTop = 0;
    要取值,也要取 master.curLeft!就算你的<table id=master curLeft =-200 > table 添加这个属性curLeft !你也不能只能用 getAttribute 来获取属性值。只有IE才支持直接用. 来访问自定义属性!
      

  4.   

    我调试了一下,IE下 eval("master") 居然不是我想象中的 document.getElementById("master")结果居然不是那个ID是 "master" 的table 对象,居然是 var master = new Object('element')!
    这个对象!看来是以前没究竟过eval!
    他是结算一个字符串的值 !  "master" 这个字符串刚好是一个全局变量名称!所以获取到的是master  这个全局变量!1、你可以直接用 master 替换所有的 eval(layerName)!2、document.all[layerName].style.top = eval(layerName).curTop
    ==>
    document.getElementById("master").style.top = master.curTop +"px";
    3、 FF下css 不兼容,那个右边小图片没显示,所以连mouseover 都没触发!
    你自己改一下!我css 很菜!
      

  5.   

    我就用你这段代码调试的,我都没改!
    ff 下,主要是css 不兼容!
    这样设置坐标值就可以, px 一定要加
    document.getElementById("master").style.top = master.curTop +"px";
      

  6.   

    那你可以发给我吗? 非常感谢! [email protected]
      

  7.   

    刚刚仔细看了看,不是你发的帖子,不过问的是一个问题,我以为都是你发的呢! http://topic.csdn.net/u/20101118/16/58380b39-5938-4378-9e40-691cdc808c1d.html?77122<script language="javascript" type="text/javascript"> 
    function moveAlong(layerName, paceLeft, paceTop, fromLeft, fromTop)
    {
    clearTimeout(master.timer)
    if(master.curLeft != fromLeft)
    {
    if((Math.max(master.curLeft, fromLeft) - Math.min(master.curLeft, fromLeft)) < paceLeft){master.curLeft = fromLeft;}
    else if(master.curLeft < fromLeft){master.curLeft = master.curLeft + paceLeft;}
    else if(master.curLeft > fromLeft){master.curLeft = master.curLeft - paceLeft;}
    masterDiv.style.left = master.curLeft+"px";}
    if(master.curTop != fromTop)
    {
      if((Math.max(master.curTop, fromTop) - Math.min(master.curTop, fromTop)) < paceTop)
      {master.curTop = fromTop}
    else if(master.curTop < fromTop){master.curTop = master.curTop + paceTop;}
    else if(master.curTop > fromTop){master.curTop = master.curTop - paceTop;}
    masterDiv.style.top = master.curTop+"px";}
    master.timer=setTimeout(function(){ moveAlong(layerName, paceLeft, paceTop, fromLeft, fromTop);},30)
    }function setPace(layerName, fromLeft, fromTop, motionSpeed)
    {master.gapLeft = (Math.max(master.curLeft, fromLeft) - Math.min(master.curLeft, fromLeft))/motionSpeed
    master.gapTop = (Math.max(master.curTop, fromTop) - Math.min(master.curTop, fromTop))/motionSpeed
    moveAlong(layerName, master.gapLeft, master.gapTop, fromLeft, fromTop)
    }
    function FixY()
    {
    masterDiv.style.top = (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop)+90 +"px";

       
    window.onerror = function(){}
    var expandState = 0;function expand(){ if(expandState == 0){setPace('master', 0, 10, 10); if(ie){document.menutop.src = 'Images/menui.jpg'}; expandState = 1;}
    else{setPace('master', -186, 10, 10); if(ie){document.menutop.src='Images/menuo.jpg'}; expandState = 0;}
    }
    document.write("<style type=text/css>#master {LEFT: -186px; POSITION: absolute; TOP: 90px; VISIBILITY: visible; Z-INDEX: 999}</style>")
    document.write("<table id=master width='218px' border='0' cellspacing='0' cellpadding='0'><tr><td></td><td rowspan='2' valign='top' style='width:30px;height:400px;background-color:Red;' onmouseover='expand()'><img id=menu border=0 height=100 name=menutop src=Images/menuo.jpg width=30></td></tr>");
    document.write("<tr><td valign='top'><table width='101%' border='0' cellpadding='0'><tr><td height='400' valign='top'><table width=100% height='100%' border=0 cellpadding=0 cellspacing=5 bordercolor='#666666' bgcolor=#006699 style=FILTER: alpha(opacity=90)><tr>");
    document.write("<td align='center' bordercolor='#ecf6f5'><font color=FFFFFF>ONLINE SERVICES<br><font size=+0.5><strong>在线服务中心</strong></font></font& amp; gt;</td></tr><tr><td valign='top' bordercolor='#ecf6f5' align='center'>");
    document.write("<iframe width='100%' marginwidth='0' marginheight='0' height='350' src='/kfu.html' frameborder=0 allowTransparency='true'></iframe></td></tr></table></td></tr></table></td></tr></table>");
    var ie = !!document.all;
    var master ={};
    master.curLeft = -186; master.curTop = 10;
    master.gapLeft = 0; master.gapTop = 0;
    master.timer = null;
    var masterDiv = null;
    (function(){
    masterDiv = document.getElementById("master");
    setInterval('FixY()',100);
    })();
    </script>