以下代码实现上下左右滚动 包括图片文字。
<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技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </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技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </td>
<td nowrap>headsen CDDN技术博客 </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,当移动元素满足某种尺寸时,移动一会就停了。
-->