javascript 文字滚动

 

1.向上滚动

 

 

<div id="ntice" style="overflow:hidden;width:275px; height :196px; margin-top:4px;">
     
<div id="ntice1" >
       
<ul>
                     
<li>内容</li>
                      
       
</ul>
       
</div>
     
<div  id="ntice2"></div> 
    
</div>

 

 

<script language="javascript" type ="text/javascript"> 
var speed=50
ntice2.innerHTML
=ntice1.innerHTML 
function Marquee(){ 
if(ntice2.offsetTop-ntice.scrollTop<=0
ntice.scrollTop
-=ntice1.offsetHeight 
else
ntice.scrollTop
++ 


var MyMar=setInterval(Marquee,speed) 
ntice.onmouseover
=function() {clearInterval(MyMar)} 
ntice.onmouseout
=function() {MyMar=setInterval(Marquee,speed)} 
</script>

 

2.左滚动

 

 

<div  id="demo" style="overflow:hidden;width:850px;height:100px;">
     
<table>
        
<tr>
            
<td id="demo1">
               
<table >
               
<tr>
                  
<td>滚动内容</td>
              
<tr>
            
</table>
            
            
</td>
         
            
<td id="demo2"></td>
            
        
</tr>
     
</table>
  
</div>

 

 

 

<script   language="JavaScript" type="text/javascript">
             
var speed=30
             demo2.innerHTML
=demo1.innerHTML
             
function Marquee(){
             
if(demo2.offsetWidth-demo.scrollLeft<=0)
             demo.scrollLeft
-=demo1.offsetWidth
             
else{
             demo.scrollLeft
++
             }
             }
             
var MyMar=setInterval(Marquee,speed)
             demo.onmouseover
=function() {clearInterval(MyMar)}
             demo.onmouseout
=function() {MyMar=setInterval(Marquee,speed)}
</script>

 

 

posted @ 2009-05-23 11:32  张巍的博客  阅读(1804)  评论(1编辑  收藏  举报