<style>
#demo
{
overflow:hidden;height:150;width:90;
background:#214984;color:#ffffff;
}
</style>
<div id=demo>
<div id=demo1>
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
<img src="http://www.haao.cn/logo.gif">
</div>
<div id=demo2></div>
</div>
<!-- 向下滚动 -->
<script>
var speed=50
demo2.innerHTML=demo1.innerHTML //克隆demo1为demo2
function Marquee()
{
if(demo2.offsetTop-demo.scrollTop<=0) //当滚动至demo1与demo2交界时
{ demo.scrollTop-=demo1.offsetHeight } //demo跳到最顶端
else
{ demo.scrollTop++ }
}
var MyMar=setInterval(Marquee,speed)//设置定时器 //鼠标移上时清除定时器达到滚动停止的目的
demo.οnmοuseοver=function() {clearInterval(MyMar)} //鼠标移开时重设定时器
demo.οnmοuseοut=function(){MyMar=setInterval(Marquee,speed)} //MyMar就代表每隔50毫秒就执行Marquee这个函数。
</script>
-->
<!-- 向下滚动
<script>
var speed=30
demo2.innerHTML=demo1.innerHTML
demo.scrollTop=demo.scrollHeight
function Marquee(){
if(demo1.offsetTop-demo.scrollTop>=0)
demo.scrollTop+=demo2.offsetHeight
else{
demo.scrollTop--
}
}
var MyMar=setInterval(Marquee,speed)
demo.οnmοuseοver=function() {clearInterval(MyMar)}
demo.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)}
</script>
-->
以上为上下移动
/**********************************************/
以下为左右移动
<style>
#demo
{
overflow:hidden;width:600px;color:#ffffff;
}
</style>
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0">
<tr><td id="demo1" valign="top" align="center">
<table cellpadding="2" cellspacing="0" border="0">
<tr align="center">
<td colspan=6>
说明:<br>
offsetWidth:offsetHeight:scrollTop等说明,参照:<br>
http://www.cnblogs.com/nianshi/archive/2008/12/29/1364637.html
</td>
</tr>
<tr align="center">
<td><img src="http://www.haao.cn/logo.gif" width="88"></td>
<td><img src="http://www.haao.cn/logo.gif" width="88"></td>
<td><img src="http://www.haao.cn/logo.gif" width="88"></td>
<td><img src="http://www.haao.cn/logo.gif" width="88"></td>
<td><img src="http://www.haao.cn/logo.gif" width="88"></td><td><img src="http://www.haao.cn/logo.gif" width="88"></td>
<td><img src="http://www.haao.cn/logo.gif" width="88"></td>
</tr>
</table>
</td>
<td id="demo2" valign="top"></td>
</tr>
</table>
</div>
<!-- 向左滚动
<script>
var speed=10//速度数值越大速度越慢
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetWidth-demo.scrollLeft<=0)
{ demo.scrollLeft-=demo1.offsetWidth } //下下滚动的是ScrollTop和OffsetHeight。这里左右的是scrollLeft和demo1.offsetWidth 。
else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.οnmοuseοver=function() {clearInterval(MyMar)}
demo.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)}
</script>
-->
<!-- 向右滚动 -->
<script>
var speed=10//速度数值越大速度越慢
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else{
demo.scrollLeft--
}
}
var MyMar=setInterval(Marquee,speed)
demo.οnmοuseοver=function() {clearInterval(MyMar)}
demo.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)}
</script>