js不间断向左滚动代码
-
来源:石家庄网站建设 发表时间: 2011年02月25日 作者:石家庄轻程网络 浏览次数: 次
<style type="text/css">
h1 {
font:400 16px/1 "Microsoft YaHei",KaiTi_GB2312,SimSun
}
#marquee {
position:relative;
width: 400px;
overflow:hidden;
border: 10px solid #B45B3E;
}
#marquee img {
border:0px;
}
#marquee dl, #marquee dt,#marquee dd,#marquee a {
float:left;
margin:0;
padding:0;
}
#marquee dl{
width:1000%;
height:150px;
}
</style>
<script type="text/javascript">
var Marquee = function(id){
try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
var container = document.getElementById(id),
original = container.getElementsByTagName("dt")[0],
clone = container.getElementsByTagName("dd")[0],
speed = arguments[1] || 10;
clone.innerHTML=original.innerHTML;
var rolling = function(){
if(container.scrollLeft == clone.offsetLeft){
container.scrollLeft = 0;
}else{
container.scrollLeft++;
}
}
var timer = setInterval(rolling,speed)//设置定时器
container.onmouseover=function() {clearInterval(timer)}//鼠标移到marquee上时,清除定时器,停止滚动
container.onmouseout=function() {timer=setInterval(rolling,speed)}//鼠标移开时重设定时器
}
window.onload = function(){
Marquee("marquee");
}
</script>
<dl id="marquee">
<dt>
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" >
<img src="http://net.wdsjz.com/UpFiles/Article/2011/1/12/2011011250804629.jpg" > </dt>
<dd></dd>
</dl>