<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
ul { padding:0; margin:0; }
li { list-style:none; }
body { background:#333; }
#pic { width:400px; height:500px; position:relative; margin:0 auto; background:url(img/loader_ico.gif) no-repeat center #fff; }
#pic img { width:400px; height:500px; }
#pic ul { width:40px; position:absolute; top:0; right:-50px; }
#pic li { width:40px; height:40px; margin-bottom:4px; background:#666; }
#pic .active { background:#FC3; }
#pic span { top:0; }
#pic p {bottom:0; margin:0;}
#pic p,#pic span { position:absolute; left:0; width:400px; height:30px; line-height:30px; text-align:center; color:#fff; background:#000; }
</style>
</head>
<body>
<div id="pic">
<img src=""/>
<span>数量正在加载中……</span>
<p>文字说明正在加载中……</p>
<ul>
</ul>
</div>
<script>
var oDiv=document.getElementById("pic");
var oImg=oDiv.getElementsByTagName("img")[0];
var ospan=oDiv.getElementsByTagName("span")[0];
var op=oDiv.getElementsByTagName("p")[0];
var oUI=oDiv.getElementsByTagName('ul')[0];
var alis=oUI.getElementsByTagName('li');
var arrSrc=['img/1.png','img/2.png','img/3.png','img/4.png'];
var arrText=['PIC1','PIC2','PIC3','PIC4'];
var num=0;
var oldLi = null;
for(var i=0;i<arrSrc.length;i++)
{
oUI.innerHTML+="<li></li>";
}
function fnTab(){
oImg.src = arrSrc[num];
ospan.innerHTML = 1+num+' / '+arrSrc.length;
op.innerHTML = arrText[num];
for( var i=0; i<alis.length; i++ ){
alis[i].className = '';
//alis[i].style.backgroundImage="url(img/1.png)";
}
alis[num].className = 'active';
}
setTimeout(function()
{
fnTab();
},1000);
for( var i=0; i<alis.length; i++ ){
alis[i].index = i; // 索引值
alis[i].onclick = function (){
num = this.index;
fnTab();
};
}
</script>
</body>
</html>
js-图片切换实例
最新推荐文章于 2024-03-05 10:52:18 发布