日期:2014-05-16  浏览次数:20377 次

javascript问题....等等高手的出现~~~
<!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>  
<style>  
<!--  
td   {   font-size:   12px   }  
-->  
</style>  
</head>  
<div   id=imga1   style= "overflow:hidden;height:98px;width:418px;   margin-left:auto;   margin-right:auto ">  
<div   id=imga2>  
<table   border= "0 "   cellpadding= "0 "   cellspacing= "0 "   width= "100% ">  
<tr>  
<td   height= "100 "   align= "center ">   <img   src= "/1.jpg "   width= "374 "   height= "72 "   style= "border:   1px   solid   #000000 "   />      
<br>  
111111111111111111111111111111111 </td>  
</tr>  
<tr>  
<td   height= "100 "   align= "center ">   <img   src= "/1.jpg "   width= "374 "   height= "72 "   style= "border:   1px   solid   #000000 "   />      
<br>  
222222222222222222222222222222222 </td>  
</tr>  
</table>  
</div>  
<div   id=imga3> </div>  
</div>  
<script>  
var   speedia=1  
imga3.innerHTML=imga2.innerHTML  
function   Marqueeia(){  
if(imga3.offsetTop-imga1.scrollTop <=0)  
imga1.scrollTop-=imga2.offsetHeight  
else{  
imga1.scrollTop++  

//这里是我自己写入的代码  
if((imga1.scrollTop-1)%100==0){clearInterval(MyMaria);  
window.setTimeout(function()   {MyMaria=setInterval(Marqueeia,speedia)},1000)}  
//结束  

}  
}  
var   MyMaria=setInterval(Marqueeia,speedia)  

imga1.onmouseover=function()   {clearInterval(MyMaria)}  
imga1.onmouseout=function()   {MyMaria=setInterval(Marqueeia,speedia)}  
</script>  

基本上是正常的,但是就是鼠标移到图片上后,在移出,重复来回移几次就不正常了。

------解决方案--------------------
用个比较笨的办法改的:
<script>
var speedia=10
var flag=1
imga3.innerHTML=imga2.innerHTML
function Marqueeia(){
if(imga3.offsetTop-imga1.scrollTop <=0)
imga1.scrollTop-=imga2.offsetHeight
else{
imga1.scrollTop++

//这里是我自己写入的代码
if((imga1.scrollTop-1)%100==0){clearInterval(MyMaria);
flag=0
window.setTimeout(function() {flag=1;MyMaria=setInterval(Marqueeia,speedia)},1000)}
//结束

}
}
var MyMaria=setInterval(Marqueeia,speedia)

imga1.onmouseover=function() {clearInterval(MyMaria)}
imga1.onmouseout=function() {if(flag){MyMaria=setInterval(Marqueeia,speedia)}}
</script>