首页 > 代码库 > 无缝滚动--垂直方向

无缝滚动--垂直方向

<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" " http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无缝滚动</title>
<style type="text/css">
img{
border:0;
height:100px; width:150px;
}
td img{
margin:0 10px;
}
</style>
</head>
<body>
<!-- 纵向向无缝滚动-->
<div id="demo" style="overflow:hidden;height:350px;width:150px">
<div id="demo1">
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/haier_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/ts_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/jykj_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/jz_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/klc_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/lp_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/smsx_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/lf_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/yd_logo.png"></a>
<a href="http://www.mamicode.com/#" target="_blank"><img src="http://www.mamicode.com/images/wpt_logo.png"></a>
</div>
<div id="demo2"></div>
</div>
<script>
var speed=40;
var demo2=document.getElementById("demo2");
var demo1=document.getElementById("demo1");
var demo=document.getElementById("demo");
demo2.innerHTML=demo1.innerHTML
function Marquee(){
/*向上滚动*/
/*if(demo2.offsetTop-demo.scrollTop<=0){
demo.scrollTop-=demo1.offsetHeight;
}else{
demo.scrollTop++;
}*/
/*向下滚动*/
if(demo.scrollTop<=0){
demo.scrollTop+=demo1.offsetHeight;
}else{
demo.scrollTop--;
}
}
var MyMar=setInterval(Marquee,speed);
demo.onmouseover=function() {clearInterval(MyMar)}
demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
</body>
</html>