循环滚动的图片
2007-12-19 16:26
176 查看
在一个小的范围内显示多张图片
1.向上滚动的图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo style="OVERFLOW: hidden; WIDTH: 160px; COLOR: #ffffff; HEIGHT: 240px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo1>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<center>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--从这里开始换成你的内容-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="1.gif" width=150 height=120 border=0 alt="第一张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="2.gif" width=150 height=120 border=0 alt="第二张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="3.gif" width=150 height=120 border=0 alt="第三张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--内容结束-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</center>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo2></DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT Language="JavaScript">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo2.innerHTML = demo1.innerHTML; //克隆demo1为demo2
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var speed = 30; //滚动速度,数字越小速度越快
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function Marquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//内容滚动主函数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(demo2.offsetTop-demo.scrollTop<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//当滚动至demo1与demo2交界时
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollTop-=demo1.offsetHeight; //demo跳到最顶端
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollTop++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
initialize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function initialize()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
timer = setTimeout("Marquee()", speed);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function StopMarquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
clearInterval(timer);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//清除定时器达到滚动停止的目的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
initialize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.onmouseover=StopMarquee //鼠标移上时清除定时器达到滚动停止的目的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
demo.onmouseout=initialize //鼠标移开时重设定时器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
本例充分利用了图层的样式(OVERFLOW:
hidden),即超出部分不显示,并利用了两个相同内容图层作为过渡,因此看上去就像首尾相连的内容一直在滚动一样。
2.用按钮控制横向滚动的图片 (向左或是向右)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table cellspacing="0" cellpadding="0" width="565" border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="right" width="9"><img id="Left" style="CURSOR: hand" height="158" src="images/tejia/l.gif" width="24" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="left" width="18"> </td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><div id="demo" style="OVERFLOW: hidden; WIDTH: 565px">//控制长度
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table cellpadding="0" width="100%" border="0"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellspace="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td id="demo1" valign="top"><table cellspacing="0" cellpadding="0" width="100%"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff"><img src="images/tejia/01.jpg" width="146" height="130" /></td> //你的第一张图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--从这里开始换成你的内容-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<img src="images/tejia/02.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><img src="images/tejia/03.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><img src="images/tejia/04.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--内容结束-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff"><a href="#"><img src="images/tejia/24.jpg" width="146" height="130" border="0" /></a></td>//你的最后一张图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td id="demo2"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
valign="top"></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</div></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="right" width="18"> </td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="left" width="9"><img id="right"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
style="CURSOR: hand" height="158"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
src="images/tejia/r.gif" width="24"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
name="right" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<INPUT
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
id=direction type=hidden value=0>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var speed=30;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo2.innerHTML=demo1.innerHTML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT language=javascript event=onclick for=right>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=demo.scrollWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
document.all["direction"].value = "MarqueeRight";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT language=javascript event=onclick for=Left>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
document.all["direction"].value = "MarqueeLeft";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function Marquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(document.all["direction"].value=="MarqueeRight")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(demo.scrollLeft<=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft+=demo2.offsetWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft--
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if(document.all["direction"].value=="MarqueeLeft")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(demo2.offsetWidth-demo.scrollLeft<=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft-=demo1.offsetWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft++
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var MyMar=setInterval(Marquee,speed)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
demo.onmouseover=function() ...{clearInterval(MyMar)}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
demo.onmouseout=function() ...{MyMar=setInterval(Marquee,speed)}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
1.向上滚动的图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo style="OVERFLOW: hidden; WIDTH: 160px; COLOR: #ffffff; HEIGHT: 240px">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo1>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<center>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--从这里开始换成你的内容-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="1.gif" width=150 height=120 border=0 alt="第一张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="2.gif" width=150 height=120 border=0 alt="第二张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<IMG src="3.gif" width=150 height=120 border=0 alt="第三张">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--内容结束-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</center>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<DIV id=demo2></DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</DIV>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT Language="JavaScript">...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo2.innerHTML = demo1.innerHTML; //克隆demo1为demo2
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var speed = 30; //滚动速度,数字越小速度越快
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function Marquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//内容滚动主函数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(demo2.offsetTop-demo.scrollTop<=0)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//当滚动至demo1与demo2交界时
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollTop-=demo1.offsetHeight; //demo跳到最顶端
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollTop++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
initialize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function initialize()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
timer = setTimeout("Marquee()", speed);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function StopMarquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
clearInterval(timer);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//清除定时器达到滚动停止的目的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
initialize();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.onmouseover=StopMarquee //鼠标移上时清除定时器达到滚动停止的目的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
demo.onmouseout=initialize //鼠标移开时重设定时器
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
本例充分利用了图层的样式(OVERFLOW:
hidden),即超出部分不显示,并利用了两个相同内容图层作为过渡,因此看上去就像首尾相连的内容一直在滚动一样。
2.用按钮控制横向滚动的图片 (向左或是向右)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table cellspacing="0" cellpadding="0" width="565" border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="right" width="9"><img id="Left" style="CURSOR: hand" height="158" src="images/tejia/l.gif" width="24" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="left" width="18"> </td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><div id="demo" style="OVERFLOW: hidden; WIDTH: 565px">//控制长度
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<table cellpadding="0" width="100%" border="0"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellspace="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td id="demo1" valign="top"><table cellspacing="0" cellpadding="0" width="100%"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff"><img src="images/tejia/01.jpg" width="146" height="130" /></td> //你的第一张图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--从这里开始换成你的内容-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<img src="images/tejia/02.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><img src="images/tejia/03.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td><img src="images/tejia/04.jpg" width="146" height="130" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<!--内容结束-->
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="middle"><table bordercolor="#f0ece9" cellspacing="5"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
cellpadding="0" width="111" bgcolor="#f0ece9"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
border="0">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td bgcolor="#ffffff"><a href="#"><img src="images/tejia/24.jpg" width="146" height="130" border="0" /></a></td>//你的最后一张图片
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td id="demo2"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
valign="top"></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</div></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="right" width="18"> </td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<td align="left" width="9"><img id="right"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
style="CURSOR: hand" height="158"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
src="images/tejia/r.gif" width="24"
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
name="right" /></td>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tr>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</tbody>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</table>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</body>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<INPUT
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
id=direction type=hidden value=0>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var speed=30;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo2.innerHTML=demo1.innerHTML
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT language=javascript event=onclick for=right>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=demo.scrollWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
document.all["direction"].value = "MarqueeRight";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT language=javascript event=onclick for=Left>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
document.all["direction"].value = "MarqueeLeft";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
<SCRIPT>...
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
function Marquee()...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(document.all["direction"].value=="MarqueeRight")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(demo.scrollLeft<=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft+=demo2.offsetWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft--
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if(document.all["direction"].value=="MarqueeLeft")
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(demo2.offsetWidth-demo.scrollLeft<=0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft-=demo1.offsetWidth
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
else...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
demo.scrollLeft++
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var MyMar=setInterval(Marquee,speed)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
demo.onmouseover=function() ...{clearInterval(MyMar)}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
demo.onmouseout=function() ...{MyMar=setInterval(Marquee,speed)}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</SCRIPT>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
相关文章推荐
- 图片循环滚动代码(无缝滚动)(分别向上、下、左、右)
- Jquery 无缝图片循环滚动(仿marquee)
- 左右图片循环滚动停顿一下后继续
- 图片自动滚动,循环播放Android auto-scroll-view-pager(转载)
- 滚动视图(UIScrollView)无限无缝左右切换图片,自动顺序加逆序循环播放图片
- Unity3D循环滚动的背景图片?制作方法!!!!
- 图片四个方向无缝循环滚动代码
- 文字/图片向上无限循环滚动
- 网页图片无缝循环滚动html代码
- 图片无缝循环滚动
- 使用UIScrollView 结合 UIImageView 实现图片循环滚动
- ViewPager制作循环滚动图片
- JS实现div内部的文字或图片自动循环滚动代码
- html之实现一组图片循环且首尾相连的滚动效果
- JQUERY图片循环滚动
- jQuery插件--图片文字向上向左循环滚动
- 图片循环滚动效果
- 利用ViewPager实现图片循环滚动
- VC++实现一张图片循环滚动
- 使用ViewPager实现循环滚动播放图片广告