实现功能:默认向左自动滚动图片,用鼠标可以控制向左向右滚动,具体实现方法看如下代码:
| 以下是代码片段: <a onMouseOver="r_left();">[向左]</a> <div id="demo" style="float:left;overflow:hidden;width:810px;height:140px;margin-left:10px;"> <TABLE cellPadding="0" width="100%" align="left" border="0" cellSpacing="0"> <TR> <!--------------------demo1---------------------> <TD id="demo1" vAlign="top"> <TABLE cellSpacing="0" cellPadding="0"> <TR vAlign="top"> <TD vAlign="top" noWrap> <TABLE cellSpacing="0" cellPadding="0" align="center" border="0"> <TR> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p1" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p1" target="_parent">图片一</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p2" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p2" target="_parent">图片二</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p3" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p3" target="_parent">图片三</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p4" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p4" target="_parent">图片四</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p5" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p5" target="_parent">图片五</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p5" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p5" target="_parent">图片六</A></TD></TR> </TABLE> </TD> <TD align="middle"> <TABLE cellSpacing="0" cellPadding="0" width="140" align="center" border="0"> <TR><TD align="middle" height="120"><A href="product.html#p5" target="_parent"><img src="http://www.noonenet.cn/images/logo.gif" width="112" height="45" border="0"/></A></TD></TR> <TR><TD align="middle" height="20"><A href="product.html#p5" target="_parent">图片七</A></TD></TR> </TABLE> </TD> </TR></TABLE></TD></TR></TABLE></TD> <!-------------------demo2---------------------> <TD id=demo2 width="0"></TD> </TR></TABLE> <SCRIPT language="javascript"> <!-- var dir=1 //每步移动像素,大=快 var speed=1 //循环周期(毫秒)大=慢 document.getElementById("demo2").innerHTML = document.getElementById("demo1").innerHTML; function Marquee(){//正常移动 if (dir>0 && (document.getElementById("demo2").offsetWidth-document.getElementById("demo").scrollLeft)<=0) document.getElementById("demo").scrollLeft=0 if (dir<0 &&(document.getElementById("demo").scrollLeft<=0)) document.getElementById("demo").scrollLeft=document.getElementById("demo2").offsetWidth document.getElementById("demo").scrollLeft+=dir document.getElementById("demo").onmouseover=function() {clearInterval(MyMar)}//暂停移动 document.getElementById("demo").onmouseout=function() {MyMar=setInterval(Marquee,speed)}//继续移动 } function r_left(){if (dir=-1)dir=1}//换向左移 function r_right(){if (dir=1)dir=-1}//换向右移 var MyMar=setInterval(Marquee,speed) //--> </SCRIPT> </div><a onMouseOver="r_right();">[向右]</a> |
原载: No.1网络工作室 http://www.noonenet.cn/