[经典代码]图片不断循环向左滚动代码(可修改滚动方向)

<DIV id=demo style="OVERFLOW: hidden; WIDTH: 450px; COLOR: #ffffff">
<TABLE border=0 cellPadding=0 cellSpacing=0 cellspace="0">
<TBODY>
<TR>
<TD id=demo1 vAlign=top align=middle>
<TABLE cellSpacing=0 cellPadding=2 border=0>
<TBODY>
<TR align=middle>
<TD><IMG src=\'#\'" href="http://www.year80.cn/images/simblack/zhu.jpg"></TD">http://www.year80.cn/images/simblack/zhu.jpg"></TD>
<TD><IMG src=\'#\'" href="http://www.year80.cn/images/simblack/zhu.jpg"></TD">http://www.year80.cn/images/simblack/zhu.jpg"></TD>
<TD><IMG src=\'#\'" href="http://www.year80.cn/images/simblack/zhu.jpg"></TD">http://www.year80.cn/images/simblack/zhu.jpg"></TD>
<TD><IMG src=\'#\'" href="http://www.year80.cn/images/simblack/zhu.jpg"></TD></TR></TBODY></TABLE></TD">http://www.year80.cn/images/simblack/zhu.jpg"></TD></TR></TBODY></TABLE></TD>
<TD id=demo2 vAlign=top></TD></TR></TBODY></TABLE></DIV>
<SCRIPT>
var speed=1//速度数值越大速度越慢,demo2.offsetWidth=demo1.offsetWidth=固定值
demo2.innerHTML=demo1.innerHTML
function Marquee(){
if(demo2.offsetWidth-demo.scrollLeft<=0)//其实demo.scrollLeft是有最大值的,和demo0.width,引用的图片的width有关系。demo过了一半(每半内容一样的),重新开始循环
demo.scrollLeft-=demo1.offsetWidth
else{
demo.scrollLeft++//不断的增加,相当于父容器的滚动条不断是缩小;但由于OVERFLOW: hidden; (滚动条不可见)
}
}
var MyMar=setInterval(Marquee,speed)
demo. {clearInterval(MyMar)}
demo. {MyMar=setInterval(Marquee,speed)}
</SCRIPT>

向上滚动:

<script>
var speed=3
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. {clearInterval(MyMar)}
demo. {MyMar=setInterval(Marquee,speed)}
</script>


向下滚动:
<script>
var speed=3
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. {clearInterval(MyMar)}
demo. {MyMar=setInterval(Marquee,speed)}
</script>


向右滚动:

<script>
var speed=3
demo2.innerHTML=demo1.innerHTML
demo.scrollLeft=demo.scrollWidth
function Marquee(){
if(demo.scrollLeft<=0)
demo.scrollLeft+=demo2.offsetWidth
else{
demo.scrollLeft--
}
}
var MyMar=setInterval(Marquee,speed)
demo. {clearInterval(MyMar)}
demo. {MyMar=setInterval(Marquee,speed)}
</script>

你可能感兴趣的:(JavaScript,js,职场,脚本,休闲)