亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么點擊下一張的時候第四張圖片不能回到第一張,點擊上一張沒有問題,,,,,

<!DOCTYPE html>

<html>

<head>

<title>焦點圖輪播</title>

<meta charset="utf-8">

<style type="text/css">

*{

margin: 0;

padding: 0;

}

a{

text-decoration: none;

color: #fff;

}

#contenter{

width: 725px;

height: 400px;

border:3px solid #333;

overflow: hidden;

position: relative;

}

#btn{

width: 150px;

text-align: center;

position: absolute;

z-index: 2;

bottom: 20px;

left: 200px;

}

#btn a{

width: 20px;

height: 20px;

background-color: #fff;

border-radius: 50px;

border: 2px solid #000;

display: inline-block;

opacity: 0.6;

margin:0 5px;

}

#btn .on{

background-color: yellow;

}

#Jiao{

width: 725px;

position: absolute;

top: 175px;

z-index: 2;

display: none;

}

#contenter:hover #Jiao{

display: block;

}

.jiao{

width: 50px;

height: 50px;

text-align: center;

line-height: 50px;

background-color: #000;

display: inline-block;

opacity: 0.6;

}

.jiao:hover{

opacity: 1;

transition: 1s;

}

#prev{

margin-right: 620px;

}

#img{

width: 4410px;

height: 400px;

position: absolute;

z-index: 1;

}

#img img{

float: left;

}


</style>

<script type="text/javascript">

// 當頁面加載完畢后才獲取元素

window.onload=function(){

var Contenter=document.getElementById("contenter");

var Img=document.getElementById("img");

var Btn=document.getElementById("btn").getElementsByTagName('a');

var Prev=document.getElementById("prev");

var Next=document.getElementById("next");

var index=1;

function lightbtn(){

for(i=0;i<Btn.length;i++){

if(Btn[i].className=="on"){

Btn[i].className="";

}

}

Btn[index-1].className="on";

}

function animate(offset){

var newleft=parseInt(Img.style.left)+offset;

Img.style.left=newleft+"px";

if (newleft>-730) {

Img.style.left=-2920+"px";

}

if (newleft<-2920) {

Img.style.left=-730+"px";

}

}

Next.onclick=function(){

if(index==5){

index=1;

index+=1;

}

else{

index+=1;

}

lightbtn();

animate(-730);

}

Prev.onclick=function(){

if(index==1){

index=5;

index-=1;

}

else{

index-=1;

}

lightbtn();

animate(730);

}

}

</script>

</head>

<body>

<div id="contenter">

<div id="img" style="left:-730px;">

<a href="">

<img src="j4.jpg"></a>

<a class="on" href="">

<img src="j1.jpg"></a>

<a href="">

<img src="j2.jpg"></a>

<a href="">

<img src="j3.jpg"></a>

<a href="">

<img src="j4.jpg"></a>

<a href="">

<img src="j1.jpg"></a>

</div>

<div id="btn">

<a href="" class="on"></a>

<a href=""></a>

<a href=""></a>

<a href=""></a>

</div>

<div id="Jiao">

<a href="javascript:;" id="prev" class="jiao">&lt;</a>

<a href="jacascript:;" id="next" class="jiao">&gt;</a>

</div>

</div>


</body>

</html>

57d510a9000121fc05000458.jpg

57d510aa0001d99705000275.jpg


正在回答

2 回答

這是因為你獲取的var Btn=document.getElementById("btn").getElementsByTagName('a');個數為4個。index應該從1 到4。

0 回復 有任何疑惑可以回復我~
#1

慕粉1469491289 提問者

謝謝
2016-09-11 回復 有任何疑惑可以回復我~
#2

慕粉1469491289 提問者

非常感謝個數為4.那index-1要為4不應該取到5嗎?
2016-09-11 回復 有任何疑惑可以回復我~

<!DOCTYPE html>

<html>

<head>

<title>焦點圖輪播</title>

<meta charset="utf-8">

<style type="text/css">

*{

margin: 0;

padding: 0;

}

a{

text-decoration: none;

color: #fff;

}

#contenter{

width: 725px;

height: 400px;

border:3px solid #333;

overflow: hidden;

position: relative;

}

#btn{

width: 150px;

text-align: center;

position: absolute;

z-index: 2;

bottom: 20px;

left: 200px;

}

img{

width:725px;

height:400px;

}

#btn a{

width: 20px;

height: 20px;

background-color: #fff;

border-radius: 50px;

border: 2px solid #000;

display: inline-block;

opacity: 0.6;

margin:0 5px;

}

#btn .on{

background-color: yellow;

}

#Jiao{

width: 725px;

position: absolute;

top: 175px;

z-index: 2;

display: none;

}

#contenter:hover #Jiao{

display: block;

}

.jiao{

width: 50px;

height: 50px;

text-align: center;

line-height: 50px;

background-color: #000;

display: inline-block;

opacity: 0.6;

}

.jiao:hover{

opacity: 1;

transition: 1s;

}

#prev{

margin-right: 620px;

}

#img{

width: 4410px;

height: 400px;

position: absolute;

z-index: 1;

}

#img img{

float: left;

}


</style>

<script type="text/javascript">

// 當頁面加載完畢后才獲取元素

window.onload=function(){

var Contenter=document.getElementById("contenter");

var Img=document.getElementById("img");

var Btn=document.getElementById("btn").getElementsByTagName('a');

var Prev=document.getElementById("prev");

var Next=document.getElementById("next");

var index=1;

function lightbtn(){

for(i=0;i<Btn.length;i++){

if(Btn[i].className=="on"){

Btn[i].className="";

}

}

Btn[index-1].className="on";

}

function animate(offset){

var newleft=parseInt(Img.style.left)+offset;

Img.style.left=newleft+"px";

if (newleft>-730) {

Img.style.left=-2920+"px";

}

if (newleft<-2920) {

Img.style.left=-730+"px";

}

}

Next.onclick=function(){

if(index==4){

index=1;

?// index+=1;

}

else{

index+=1;

}

lightbtn();

animate(-730);

}

Prev.onclick=function(){

if(index==1){

index=4;

// index-=1;

}

else{

index-=1;

}

lightbtn();

animate(730);

}

}

</script>

</head>

<body>

<div id="contenter">

<div id="img" style="left:-730px;">

<a href="">

<img src="../HtmlImg/4.jpg">

</a>

<a class="on" href="">

<img src="../HtmlImg/1.jpg">

</a>

<a href="">

<img src="../HtmlImg/2.jpg">

</a>

<a href="">

<img src="../HtmlImg/3.jpg">

</a>

<a href="">

<img src="../HtmlImg/4.jpg">

</a>

<a href="">

<img src="../HtmlImg/1.jpg">

</a>

</div>

<div id="btn">

<a href="" class="on"></a>

<a href=""></a>

<a href=""></a>

<a href=""></a>

</div>

<div id="Jiao">

<a href="javascript:;" id="prev" class="jiao">&lt;</a>

<a href="jacascript:;" id="next" class="jiao">&gt;</a>

</div>

</div>


</body>

</html>


0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

為什么點擊下一張的時候第四張圖片不能回到第一張,點擊上一張沒有問題,,,,,

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號