动态图片JS动态效果

来源:互联网 发布:淘宝的皇冠店铺信誉度 编辑:程序博客网 时间:2024/05/01 13:45
<style type="text/css">
<!--
.a{
border:10px #fcc solid;
}
.b{
border:none;
}
#pic{
width:500px;
height:300px;
overflow:hidden;
}
#pic0{
width:5000%;
height:300px;
}
-->
</style>
<body>
<div id="small">
<img src="" width="100" height="100" alt="1" />
<img src="" width="100" height="100" alt="2" />
<img src="" width="100" height="100" alt="3" />
<img src="" width="100" height="100" alt="4" />
</div>


<div id="pic">
<div id="pic0">
<span id="pic1"><img src="" width="500" height="300" alt="1" /><img src="" width="500" height="300" alt="2" /><img src="" width="500" height="300" alt="3" /><img src="" width="500" height="300" alt="4" /></span><span id="pic2"></span>
</div>
</div>
</body>
<script type="text/javascript">
var a = document.getElementById("small");
var b = a.getElementsByTagName("img");
var i = 0;
var pic = document.getElementById("pic");
var pic1 = document.getElementById("pic1");
var pic2 = document.getElementById("pic2");
window.onload=function(){pic.scrollLeft = 0;return false;}
pic2.innerHTML = pic1.innerHTML;


function marquee()
{
if(pic2.offsetWidth-pic.scrollLeft == 0)
{
pic.scrollLeft = 500;
}
else
{
pic.scrollLeft+=500;
}
return false;
}


function _clear(n) {
return function (){
for (var j=0; j < b.length; j++)
{
if (n!=j)
{
b[j].className = "b";//不等于显示当前边框的时候其边框为没有;
}
}
//var out = setInterval(marquee,100);
function timeout(){clearInterval(out);return false;}//清除滚动函数
setTimeout(marquee,100);
}
}


function img()
{
b[i].className = "a";
if(i>b.length-2)
{
i=0;
}
else
{
i++;
}
setTimeout(_clear(i),2000);

}
setInterval(img,2000);
</script>