代码如下:火狐下跑不起来。<!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>
</head>
<body>
 <script language="javascript" type="text/javascript">
var obj_marquee;
var marquee_spd = 4000;
var step_c = 0;
function marquee_init() {
  obj_marquee = document.getElementById("marquee");
  var obj_unit = obj_marquee.firstChild;
  var n = Math.ceil(parseInt(obj_marquee.style.height) / obj_unit.offsetHeight);
  for(var i=0; i<n; i++) obj_marquee.appendChild(obj_unit.cloneNode(true));
setInterval("step_c=0;setTimeout('marquee_show()',50)", marquee_spd);
  return;
}
function marquee_show() {
  var marquee_high = parseInt(obj_marquee.style.height);
  var step = marquee_high/12;
  if(obj_marquee.scrollTop >= obj_marquee.childNodes[1].offsetTop) {
    obj_marquee.scrollTop = 0;
    marquee_show();
    return;
  }
  obj_marquee.scrollTop += step;
  if(step_c++ < 12) setTimeout("marquee_show()", 50);
  return;
}
window.onload=marquee_init;
        </script>        <div id="marquee" style="overflow: hidden; padding: 0; height: 346px; width: 100%; border: 0px; padding: 0px;">
            <div style="border: 0px; padding: 0px">
                <!-- Marquee Body Head -->
                <div style="height: 173px; border: 0px; overflow: hidden;">
                    <a href="ad.html" target="_blank">
                        <img src="images/01.jpg" alt="" style="width:210px;height:170px;border:0;" /></a>
                </div>
                <div style="height: 173px; overflow: hidden;">
                    <a href="ad2.html" target="_blank">
                        <img src="images/01.jpg" alt="" style="width:210px;height:170px;border:0;" /></a>
                </div>
                <!-- Marquee Body Bottom -->
            </div>
        </div>
        
</body>
</html>

解决方案 »

  1.   

    请教过N个人了。。没有一个能搞定。。郁闷。。这段代码我用火狐的firebug调试也没有出现错误提示。但就是跑不起来。。在IE下没有一点问题
      

  2.   

    debug了一下,发现是obj_unit.offsetHeight这个值是undefined.
      

  3.   

    var obj_unit = obj_marquee.firstChild; 这里,获取到的是TextNode,不是Element
      

  4.   

    重写了一下,没时间说明了,LZ自己看吧。测试:FF3.5 IE6.0下班,闪人
    <!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 type="text/css">
    *{padding:0;margin:0;}
    </style>
    </head>
    <body>
    <div id="marquee" style="overflow: hidden; height: 348px; width: 100%;">
    <div style="overflow:hidden; height: 348px;width:100%;">
    <!-- Marquee Body Head -->
    <div style="height: 174px; overflow: hidden;"> <a href="ad.html" target="_blank"> <img src="01.jpg" alt="" style="float:left;display:block;width:210px;margin-top:2px;height:170px;border:0;" /></a> </div>
    <div style="height: 174px; overflow: hidden;"> <a href="ad2.html" target="_blank"> <img src="01.jpg" alt="" style="float:left;display:block;width:210px;margin-top:2px;height:170px;border:0;" /></a> </div>
    <!-- Marquee Body Bottom -->
    </div>
    </div>
    <script language="javascript" type="text/javascript"> 
    (function(id, t, s, d) {
    var box = null;
    var line = null;
    var line2 = null;
    var timeOut = t;
    var step = s;
    var mTime = d;
    var h = 0;
    setTimeout(function() {
    box = document.getElementById(id);
    if(box) {
    line = box.getElementsByTagName('div')[0];
    line2 = line.cloneNode(true);
    h = line.offsetHeight;
    box.appendChild(line2);
    setInterval(resetIt, timeOut);
    } else {
    setTimeout(arguments.callee, 50);
    };
    });
    function resetIt() {
    scrollLine();
    }
    function scrollLine() {
    var l = (box.scrollTop + step - h) < 0? box.scrollTop + step : h;
    box.scrollTop = l;
    if(l != h) {
    setTimeout(scrollLine, mTime);
    } else {
    var line3 = box.getElementsByTagName('div')[0];
    var line4 = line3.cloneNode(true);
    box.removeChild(line3);
    box.scrollTop = 0;
    box.appendChild(line4);
    }
    }
    })('marquee', 4000, 10, 40);
    </script>
    </body>
    </html>