Js圖片切換

來源:互聯網
上載者:User

標籤:ima   order   迴圈   src   button   com   blog   body   get   

        <!DOCTYPE html><html<head>

<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/1.css" />
<style>
在css中,因為p標籤有個margin ,所以margin 要置為0,filter:alpha(opacity:80)(相容IE瀏覽器); opacity:0.8(相容Firefox瀏覽器); 
p { margin:0; }
body { text-align:center; }
#box { width:400px; height:400px; border:10px solid #ccc; margin:50px auto 0; position:relative; }
a { width:40px; height:40px; background:brown; filter:alpha(opacity:80); opacity:0.8; position:absolute; top:160px; font-size:18px; color:#000; text-align:center; line-height:40px; text-decoration:none; }
a:hover { filter:alpha(opacity:30); opacity:0.3; }
#prev { left:10px; }
#next { right:10px; }
#p1 { width:400px; height:30px; line-height:30px; text-align:center; background:#000; color:#fff; font-size:14px; filter:alpha(opacity:80); opacity:0.8; position:absolute; bottom:0; left:0; }
strong { width:400px; height:30px; line-height:30px; text-align:center; background:#000; color:#fff; font-size:14px; filter:alpha(opacity:80); opacity:0.8; position:absolute; top:0; left:0; }
#img1 { width:400px; height:400px; }
span { position:absolute; width:400px; height:30px; line-height:30px; text-align:center; top:-50px; left:0; font-family:‘微軟雅黑‘; }

</style>

<script type="text/javascript" >
window.onload = function (){
var oPrev = document.getElementById(‘prev‘);
var oNext = document.getElementById(‘next‘);
var oP = document.getElementById(‘p1‘);
var oStrong = document.getElementById(‘strong1‘);
var oImg = document.getElementById(‘img1‘);
var aBtn = document.getElementsByTagName(‘input‘);
var arrUrl = [ ‘img/1.jpg‘, ‘img/2.jpg‘, ‘img/3.jpg‘, ‘img/4.jpg‘ ];
var arrText = [ ‘文字一‘, ‘文字二‘, ‘文字三‘, ‘識文斷字‘ ];
var num = 0;
var onOff = true;
//初始化
function Tab(){
oStrong.innerHTML=num+1+"/"+arrText.length;
oP.innerHTML=arrText[num];
oImg.src=arrUrl[num];

}
Tab();

aBtn[0].onclick=function(){
onOff=true;
document.getElementsByTagName("span")[0].innerHTML=‘圖片可從最後一張跳轉到第一張迴圈切換‘;

};
aBtn[1].onclick=function(){
onOff=false;
document.getElementsByTagName("span")[0].innerHTML=‘圖片只能到最後一張或只能到第一張切換‘;

};

oNext.onclick=function(){
num++;
if(onOff){
if(num==arrText.length){num=0; }

}else{
if(num==arrText.length){alert("這已經是最後一張~~~~~");
num=arrText.length-1;
}

}
Tab();

};
oPrev.onclick=function(){
num--;
if(onOff){
if(num==-1){num=arrText.length-1;}
}else{
if(num==-1){num=num+1;
alert(‘這已經是第一張了~~~~‘);}

}
Tab();

}

}

</script>

</head>
<body>

<input type="button" value="迴圈切換" />
<input type="button" value="順序切換" />


<div id="box"><span>圖片可從最後一張跳轉到第一張迴圈切換</span>
<a id="prev" href="javascript:;"><</a>
<a id="next" href="javascript:;">></a>
<p id="p1">圖片文字載入中……</p>
<strong id="strong1">圖片數量計算中……</strong>
<img id="img1" />
</div>
</body>
</html>

 

  

 

         

Js圖片切換

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.