本篇文章主要是对js+div实现图片滚动效果的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
横向
<div id=demo
onmouseout="doscroll()">
<div>
<a href="javascript:alert('发表新贴');"><img src="https://www.jb51.net/图片URL" height=20 width=104
border=0></a>
<a href="javascript:alert('发表回复');"><img src="https://www.jb51.net/图片URL" height=20 width=104
border=0></a>
</div>
</div>
<!--滚动的javascript-->
<script>
var t=demo.scrollWidth
demo1.innerHTML+=demo1.innerHTML
function doMarquee()
{
demo.scrollLeft=demo.scrollLeft<demo.scrollWidth-demo.offsetWidth?demo.scrollLeft+1:t-demo.offsetWidth
}
function doscroll()
{
sc=setInterval(doMarquee,20)
}
function stopscroll()
{
clearInterval(sc)
}
doscroll()
</script>
<!--滚动的javascript结束-->
纵向
<div>
<div>
<a href="javascript:alert('发表新贴');"><img src="https://www.jb51.net/图片URL" height=20 width=104
border=0></a>
<a href="javascript:alert('发表回复');"><img src="https://www.jb51.net/图片URL" height=20 width=104
border=0></a>
</div><div></div>
<!--滚动的javascript-->
<script>
var speed=100
demo2.innerHTML=demo1.innerHTML
function Marquees(){
if(demo2.offsetTop-demo.scrollTop<=0)
demo.scrollTop-=demo1.offsetHeight
else{
demo.scrollTop++
}
}
var MyMars=setInterval(Marquees,speed)
demo.onmouseover=function() { clearInterval(MyMars) }
demo.onmouseout=function() { MyMars=setInterval(Marquees,speed) }
zlselect('6');
</script><!--滚动的javascript结束-->
</div>
您可能感兴趣的文章: