它是可以兼容火狐了,但它过一会就停止,我想让它永远不停,但又不会修改代码,请高手帮修改,代码如下: <!--下面是向上滚动代码-->
<div id="colee" style="overflow:hidden;height:253px;width:750px;">
<div id="colee1">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
</div>
<div id="colee2"></div>
</div>
<script>
var speed=30;
var colee2=document.getElementById("colee2");
var colee1=document.getElementById("colee1");
var colee=document.getElementById("colee");
colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2
function Marquee1(){
//当滚动至colee1与colee2交界时
if(colee2.offsetTop-colee.scrollTop<=0){
colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端
}else{
colee.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
colee.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script><!--向上滚动代码结束-->
<div id="colee" style="overflow:hidden;height:253px;width:750px;">
<div id="colee1">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
</div>
<div id="colee2"></div>
</div>
<script>
var speed=30;
var colee2=document.getElementById("colee2");
var colee1=document.getElementById("colee1");
var colee=document.getElementById("colee");
colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2
function Marquee1(){
//当滚动至colee1与colee2交界时
if(colee2.offsetTop-colee.scrollTop<=0){
colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端
}else{
colee.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
colee.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script><!--向上滚动代码结束-->
两种办法解决问题:
一、重写计算offsetTop的方法。
二、将offsetTop改为offsetHeight。
function OffsetTop(obj){
var _top = obj.offsetTop;
while(obj = obj.offsetParent){
_top += obj.offsetTop;
}
return _top;
}
<!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>
<!--下面是向上滚动代码-->
<div id="colee" style="overflow:hidden;height:253px;width:750px;">
<div id="innerDom" style="height:800%;">
<div id="colee1">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
</div>
<div id="colee2"></div>
</div>
</div>
<script>
var speed=30;
var colee2=document.getElementById("colee2");
var colee1=document.getElementById("colee1");
var colee=document.getElementById("colee");
colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2
function Marquee1(){
//当滚动至colee1与colee2交界时
if(colee2.offsetHeight - colee.scrollTop<=0){
colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端
}else{
colee.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
colee.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script><!--向上滚动代码结束-->
</body>
</html>
<!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>
<!--下面是向上滚动代码-->
<div id="colee" style="overflow:hidden;height:253px;width:750px;">
<div id="innerDom" style="height:800%;">
<div id="colee1">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
<img src="img/01.gif">
<img src="img/02.gif">
<img src="img/03.gif">
<img src="img/04.gif">
</div>
<div id="colee2"></div>
</div>
</div>
<script>
function OffsetTop(obj){
var _top = obj.offsetTop;
while(obj = obj.offsetParent){
_top += obj.offsetTop;
}
return _top;
}
var speed=30;
var colee2=document.getElementById("colee2");
var colee1=document.getElementById("colee1");
var colee=document.getElementById("colee");
colee2.innerHTML=colee1.innerHTML; //克隆colee1为colee2
function Marquee1(){
//当滚动至colee1与colee2交界时
if(OffsetTop(colee2) - colee.scrollTop<=0){
colee.scrollTop-=colee1.offsetHeight; //colee跳到最顶端
}else{
colee.scrollTop++
}
}
var MyMar1=setInterval(Marquee1,speed)//设置定时器
//鼠标移上时清除定时器达到滚动停止的目的
colee.onmouseover=function() {clearInterval(MyMar1)}
//鼠标移开时重设定时器
colee.onmouseout=function(){MyMar1=setInterval(Marquee1,speed)}
</script><!--向上滚动代码结束-->
</body>
</html>