滚动字幕——左滚、右滚、上滚、下滚

以下代码实现上下左右滚动 包括图片文字。

 <div id=headsen_top style=overflow:hidden;height:100;width:90;>
 <div id=headsen_top1>
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
   <img src="
http://profile.csdn.net/headsen/picture/3.jpg">
 </div>
 <div id=headsen_top2></div>
</div>
<script>
  var speed=30
  headsen_top2.innerHTML=headsen_top1.innerHTML //克隆headsen_top1为headsen_top2
  function Marquee1(){
    //当滚动至headsen_top1与headsen_top2交界时
    if(headsen_top2.offsetTop-headsen_top.scrollTop<=0)  
      headsen_top.scrollTop-=headsen_top1.offsetHeight //headsen_top跳到最顶端
    else{
      headsen_top.scrollTop++;
    }
  }
  var MyMar1=setInterval(Marquee1,speed)//设置定时器
  //鼠标移上时清除定时器达到滚动停止的目的
  headsen_top.οnmοuseοver=function() {clearInterval(MyMar1)}
  //鼠标移开时重设定时器
  headsen_top.οnmοuseοut=function(){MyMar1=setInterval(Marquee1,speed)}
</script>
<!--向上滚动代码结束-->
<br>
<!--下面是向下滚动代码-->
<div id=headsen_bottom style=overflow:hidden;height:100;width:240;>
 <div id=headsen_bottom1>
   headsen CDDN技术博客 <br>
   headsen CDDN技术博客 <br>
   headsen CDDN技术博客 <br>
   headsen CDDN技术博客 <br>
   headsen CDDN技术博客 <br>
 </div>
 <div id=headsen_bottom2></div>
</div>
<script>
  var speed=30
  headsen_bottom2.innerHTML=headsen_bottom1.innerHTML
  headsen_bottom.scrollTop=headsen_bottom.scrollHeight
  function Marquee2(){
    if(headsen_bottom1.offsetTop-headsen_bottom.scrollTop>=0)
     headsen_bottom.scrollTop+=headsen_bottom2.offsetHeight
    else{
     headsen_bottom.scrollTop--
    }
  }
  var MyMar2=setInterval(Marquee2,speed)
  headsen_bottom.οnmοuseοver=function() {clearInterval(MyMar2)}
  headsen_bottom.οnmοuseοut=function() {MyMar2=setInterval(Marquee2,speed)}
</script>
<!--向下滚动代码结束-->
<br>
<!--下面是向左滚动代码-->
<div id="headsen_left" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="headsen_left1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
</tr>
</table>
</td>
<td id="headsen_left2" valign="top"></td>
</tr>
</table>
</div>
<script>
var speed=30//速度数值越大速度越慢
headsen_left2.innerHTML=headsen_left1.innerHTML
function Marquee3(){
  if(headsen_left2.offsetWidth-headsen_left.scrollLeft<=0)
    headsen_left.scrollLeft-=headsen_left1.offsetWidth
  else{
    headsen_left.scrollLeft++
  }    
}
var MyMar3=setInterval(Marquee3,speed)
headsen_left.οnmοuseοver=function() {clearInterval(MyMar3)}
headsen_left.οnmοuseοut=function() {MyMar3=setInterval(Marquee3,speed)}
</script>
<!--向左滚动代码结束-->
<br>
<!--下面是向右滚动代码-->
<div id="headsen_right" style="overflow:hidden;width:500px;">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="headsen_right1" valign="top" align="center">
   <table cellpadding="2" cellspacing="0" border="0">
     <tr align="center">
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
      <td nowrap>headsen CDDN技术博客&nbsp;</td>
     </tr>
   </table>
</td>
<td id="headsen_right2" valign="top"></td>
</tr>
</table>
</div>
<script>
  var speed=30//速度数值越大速度越慢
  headsen_right2.innerHTML=headsen_right1.innerHTML
  function Marquee4(){
    if(headsen_right.scrollLeft<=0)
     headsen_right.scrollLeft+=headsen_right2.offsetWidth
    else{
     headsen_right.scrollLeft--
    }
  }
 var MyMar4=setInterval(Marquee4,speed)
 headsen_right.οnmοuseοver=function() {clearInterval(MyMar4)}
 headsen_right.οnmοuseοut=function() {MyMar4=setInterval(Marquee4,speed)}
</script>
<!--向右滚动代码结束-->
<!--
 说明:上述代码存在一个BUG,当移动元素满足某种尺寸时,移动一会就停了。
-->

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值