CSS:
<style type="text/css">
#demo {
background: #FFF;
overflow:hidden;
border: 1px dashed #CCC;
width: 1000px;
height:368px;
}
#demo img {
border: 3px solid #F2F2F2;
}
#indemo {
width: 8000%;
}
#demo1 , #demo2{
float: left;
}
</style>
HTML:
<div id="demo">
<div id="indemo">
<div id="demo1">
<a href="#1"><img src="http://www.0351zhuangxiu.com/uploads/images/123.jpg" border="0" /></a>
<a href="#2"><img src="http://www.0351zhuangxiu.com/uploads/images/124.jpg" border="0" /></a>
<a href="#"><img src="http://www.0351zhuangxiu.com/uploads/images/125.jpg" border="0" /></a>
<a href="#"><img src="http://www.0351zhuangxiu.com/uploads/images/126.jpg" border="0" /></a>
<a href="#"><img src="http://www.0351zhuangxiu.com/uploads/images/127.jpg" border="0" /></a>
<a href="#"><img src="http://www.0351zhuangxiu.com/uploads/images/128.jpg" border="0" /></a>
</div>
<div id="demo2"></div>
</div>
</div>
JS向左滚动:
<script type="text/javascript">
var speed=10;//控制速度
var tab=document.getElementById("demo");
var tab1=document.getElementById("demo1");
var tab2=document.getElementById("demo2");
tab2.innerHTML=tab1.innerHTML;
function Marquee(){
if(tab2.offsetWidth - tab.scrollLeft <= 0)
tab.scrollLeft -= tab1.offsetWidth;
else{
tab.scrollLeft++;
}
console.log("tab2.offsetWidth : " + tab2.offsetWidth + "tab.scrollLeft : " + tab.scrollLeft + " tab2.offsetWidth - tab.scrollLeft = " + (tab2.offsetWidth - tab.scrollLeft));
} //定时器
var MyMar=setInterval(Marquee,speed);
//鼠标滑过停止滚动
tab.οnmοuseοver=function() {clearInterval(MyMar)};
//鼠标滑出继续滚动
tab.οnmοuseοut=function() {MyMar=setInterval(Marquee,speed)};
</script>
向上滚动:
CSS:
#indemo {
height: 8000%;
}
function Marquee1(){
if(tab2.offsetHeight - tab.scrollTop <= 0)
tab.scrollTop -= tab1.offsetHeight;
else{
tab.scrollTop++;
}
console.log("tab2.offsetHeight : " + tab2.offsetHeight + "tab.scrollTop : " + tab.scrollTop + " tab2.offsetHeight - tab.scrollTop = " + (tab2.offsetHeight - tab.scrollTop));
}
向右滚动和向下滚动以此类推进行修改!