使用JS实现图片无限循环左右滚动

时间:2023-01-29 20:39:47

<!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>JS实现图片滚动</title>
<style>
#photo {
height: 120px;
width: 700px;
margin-top: 100px;
margin-right: auto;
margin-left: auto;
border: 2px double #FF0000;
overflow: hidden;
}
#photo img {
height: 110px;
width: 160px;
}
</style>
</head>

<body>
<div id=photo>
<table align="center">
<tr>
<td width=700 height=120 align=center >
<div id=demo style="overflow:hidden;width:700px;height:120px" align=center>
<table border=0 align=center cellpadding=0 cellspacing=0 cellspace=0 >
<tr>
<td valign=top id=marquePic1>
<table cellspacing="5" cellpadding="0">
<tr>
    <td width=170 height=110 align="center"><img src="pic/fj1.gif" /></td>
    <td width=170 height=110 align="center"><img src="pic/fj2.gif" /></td>
    <td width=170 height=110 align="center"><img src="pic/fj3.gif" /></td>
    <td width=170 height=110 align="center"><img src="pic/fj4.gif" /></td>
    <td width=170 height=110 align="center"><img src="pic/fj5.gif" /></td>
    <td width=170 height=110 align="center"><img src="pic/fj6.gif" /></td>
</tr>
</table>
</td>
<td id=marquePic2 valign=top></td>
</tr>
</table>
</div>
</td></tr></table>
<SCRIPT type=text/javascript>
var speed=10
marquePic2.innerHTML=marquePic1.innerHTML
function Marquee(){
if(demo.scrollLeft>=marquePic1.scrollWidth){
demo.scrollLeft=0
}else{
demo.scrollLeft++
}
}
var MyMar=setInterval(Marquee,speed)
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}

</SCRIPT>
</div>
</body>
</html>

我在本地测试好了才放来的。图片之间的距离,整体的高度、长度请根据自己的需求来更改!

 

 

转:http://hi.baidu.com/%B7%E3%D2%B6%B2%D7%C0%CB/blog/item/3ded0fcec586c635f9dc6178.html