方法一:最简单,但是仅仅支持IE8及以上,火狐,谷歌
<marquee direction="up" scrollamount="1" style="width: 400x;height: 20px" id="">
走马灯测试第一行!<br/>
走马灯测试第二行!<br/>
走马灯测试第三行!<br/>
走马灯测试第四行!<br/>
走马灯测试第五行!<br/>
</marquee>
方法二(1):效果很好,但是没有停留效果:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>走马灯</title>
</head>
<body>
<div id="demo" style="overflow:hidden;height:20px;width:400px;cursor:pointer; line-height:20px;">
<div id="demo1">
走马灯测试第一行!<br/>
走马灯测试第二行!<br/>
走马灯测试第三行!<br/>
走马灯测试第四行!<br/>
走马灯测试第五行!<br/>
</div>
<div id="demo2"> </div>
</div>
<script>
var speed=80;
var stopTime=1;
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
var demo=document.getElementById("demo");
demo2.innerHTML=demo1.innerHTML;
var intFlag=1;
function Marquee(){
if(demo2.offsetTop-demo.scrollTop<=0) {
demo.scrollTop-=demo1.offsetHeight;
}
else{
demo.scrollTop++;
}
if (demo.scrollTop%20==0) {
clearInterval(MyMar);
for (var i = 1; i <= 1000000; i++) {
intFlag++;
};
MyMar=setInterval(Marquee,speed);
/*var nowOld = new Date();
var nowNew= new Date();
//var exitTime = now.getTime() + stopTime;
while (true) {
nowNew = new Date();
if (nowNew-nowOld > stopTime)
} */
//alert(intFlag);
};
}
var MyMar=setInterval(Marquee,speed);
demo.οnmοuseοver=function() {clearInterval(MyMar)}
demo.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)}
</script>
</body>
</html>
方法二(2):横、纵都可以!:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无缝滚动</title>
<style type="text/css">
img{
border:0;
height:100px; width:150px;
}
td img{
margin:0 10px;
}
</style>
</head>
<body>
<!-- 纵向向无缝滚动-->
<div id="demo" style="overflow:hidden;height:350px;width:200px">
<div id="demo1">
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_01.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_02.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_03.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_04.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_05.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_06.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_07.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_08.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_10.jpg"></a>
<a href="#" target="_blank"><img src="jsfile/imagesa32/gundong_11.jpg"></a>
</div>
<div id="demo2">
</div>
</div>
<script>
var speed=40;
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
var demo=document.getElementById("demo");
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.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>
<!-- 横向无缝滚动-->
<div style="margin-top:20px;">
<div id="scroll_div" style="overflow: hidden; WIDTH: 778px;" align=center>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td id="scroll_begin">
<a href="#"><img src="jsfile/imagesa32/gundong_11.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_01.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_02.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_03.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_04.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_05.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_06.jpg" border=0></a>
<a href="#"><img src="jsfile/imagesa32/gundong_07.jpg" border=0></a>
</td>
<td id="scroll_end"></td>
</tr>
</table>
</div>
</div>
<script>
var speed1=40
var scroll_end = document.getElementById("scroll_end");
var scroll_div = document.getElementById("scroll_div");
scroll_end.innerHTML=scroll_begin.innerHTML
function Marquee1(){
if(scroll_end.offsetWidth-scroll_div.scrollLeft<=0)
scroll_div.scrollLeft-=scroll_begin.offsetWidth
else{
scroll_div.scrollLeft++
}
}
var MyMar1=setInterval(Marquee1,speed1)
scroll_div.οnmοuseοver=function() {clearInterval(MyMar1)}
scroll_div.οnmοuseοut=function() {MyMar1=setInterval(Marquee1,speed1)}
</script>
</body>
</html>
方法三:实现了效果还可以停留!
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>走马灯</title>
</head>
<body>
<div id="announcement" style="width:400px; height:20px; line-height:20px; overflow: hidden;">
<div id="announcementbody" style="overflow-y:hidden;line-height: 20px; height: 20px" >
走马灯测试第一行!<br/>
走马灯测试第二行!<br/>
走马灯测试第三行!<br/>
走马灯测试第四行!<br/>
走马灯测试第五行!<br/>
</div>
</div>
<script type="text/javascript">
var speed=10;
var anndelay = 1000;
var anncount = 0;
var annheight = 20;
var annst = 0;
var announcementbody=document.getElementById("announcementbody");
var announcement=document.getElementById("announcement");
function announcementScroll()
{
if(!annst)
{
announcementbody.innerHTML += announcementbody.innerHTML;
announcementbody.scrollTop = 0;
if(announcementbody.scrollHeight > annheight*3)
{
annst = setTimeout('announcementScroll()', anndelay);
}
else
{
announcement.onmouseover = announcement.onmouseout = null;
}
return;
}
if(anncount == annheight)
{
if(announcementbody.scrollHeight - annheight <= announcementbody.scrollTop)
{
announcementbody.scrollTop = announcementbody.scrollHeight / 2 - annheight;
}
anncount = 0;
annst = setTimeout('announcementScroll()', anndelay);
}
else
{
announcementbody.scrollTop ++ ;
anncount ++ ;
annst = setTimeout('announcementScroll()', speed);
}
}
announcementScroll();
announcement.οnmοuseοver=function() {clearTimeout(annst);annst = 0;}
announcement.οnmοuseοut=function() {if(!annst) annst = setTimeout('announcementScroll()', anndelay);}
</script>
</body>
</html>
方法四:图片走马灯
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>picture auto scroll</title>
</head>
<style type="text/css">
<!--
body {
text-align: center;
margin: 0 auto;
}
TD {
FONT-SIZE: 12px;
}
ul,li,img {
padding: 0;
margin: 0;
border: 0;
list-style: none;
}
ul {
width: 168px;
margin: 0 auto;
}
ul li {
width: 49.8%;
float: left;
padding: 4px 0;
}
ul li img {
width: 66px;
height: 23px;
}
</style>
</head>
<body>
<div style="margin: 5px; padding: 3px;">
</div>
<div id=link_logo
style="OVERFLOW: hidden; margin: 0 auto; WIDTH: 160px; HEIGHT: 235px">
<div id=link_logo1 style="OVERFLOW: hidden">
<ul>
<li><a href="#" target=_blank><img
src="images/1.gif" alt="123" /></a></li>
<li><a href="#" target=_blank><img
src="images/2.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/3.gif" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
src="images/4.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/5.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/6.gif" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
src="images/7.gif" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/8.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/9.gif" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/10.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/11.gif" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/12.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/13.gif" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/14.jpg" /></a></li>
<li><a href="#" target=_blank><img
src="images/15.jpg" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/16.jpg" /></a></li>
<li><a href="#" target=_blank><img
src="images/17.jpg" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/18.gif" /></a></li>
<li><a href="#" target=_blank><img
src="images/19.gif" alt="CSS" /></a></li>
<li><a href="#" target=_blank><img
alt="CSS" src="images/20.gif" /></a></li>
</ul>
</div>
<div id=link_logo2></div>
</div>
<script>
var speed = 65
link_logo2.innerHTML = link_logo1.innerHTML
function Marquee2() {
if (link_logo2.offsetTop - link_logo.scrollTop <= 0)
link_logo.scrollTop -= link_logo1.offsetHeight
else {
link_logo.scrollTop++
}
}
var MyMar2 = setInterval(Marquee2, speed)
link_logo.onmouseover = function() {
clearInterval(MyMar2)
}
link_logo.onmouseout = function() {
MyMar2 = setInterval(Marquee2, speed)
}
</script>
<br>
<br>
<br>
<br>
</body>
</html>