2014-10-05 125 views
0

我有我的代码问题,我试图用点击(缓慢淡出)与另一个图像/ div替换图像/ div。然后当第二个图像被点击时,它会回到原来的状态。替换图像onclick

我设法得到了这么多,但我有两个问题。

1 - 似乎无法隐藏页面加载中的第二个和第四个图像,因此只有在应用点击后才会显示。

2 - 我希望能够在同一页面上多次执行此操作,但使用目前为止的代码,它仅适用于关闭images/div的代码。

请帮忙。

HTML

<div><!-- Page wrapper-->  

    <div id= "first"> 
     <a href="#" id="next"> 
      <img src="images/yb2.svg" style="height: 160px; width: 160px;"> 
     </a> 
    </div> 
    <div id="second"> 
     <a href="#" id="back"> 
      img src="images/ss-1a.jpg"> 
    </div> 
    <div id= "third"> 
     <a href="#" id="next1"> 
      <img src="images/yb2.svg" style="height: 160px; width: 160px;"> 
     </a> 
    </div> 
    <div id="forth"> 
     <a href="#" id="back2"> 
      <img src="images/ss-1a.jpg"> 
    </div> 

</div><!-- end of page wrapper--> 

jQuery的

$('#next').click(function(e){ 
    e.preventDefault(); 
    $('#first').fadeOut('slow', function(){ 
     $('#second').fadeIn('slow'); 
    }); 
}); 
$('#back').click(function(e){ 
    e.preventDefault(); 
    $('#second').fadeOut('slow', function(){ 
     $('#first').fadeIn('slow'); 
    }); 
}); 
$('#next1').click(function(e){ 
    e.preventDefault(); 
    $('#third').fadeOut('slow', function(){ 
     $('#second').fadeIn('slow'); 
    }); 
}); 
$('#back2').click(function(e){ 
    e.preventDefault(); 
    $('#forth').fadeOut('slow', function(){ 
      $('#first').fadeIn('slow'); 
    }); 
}); 
+0

你希望它能像这样工作吗? http://jsfiddle.net/matthias_h/nhq9d5qa/ – 2014-10-05 08:22:23

+1

关闭'a'在'second'和'fourth'上丢失......;} – webeno 2014-10-05 08:34:14

+0

@webeno好地方:),只是在小提琴中加入了这个,但它也是没有结束标签之前工作。 – 2014-10-05 08:44:50

回答

0

只是没带以下调整一个Fiddle:1) - 隐藏的div的ID #second和#forth我刚刚添加CSS

#second, #forth { 
    display:none; 
} 

而且就像我认为它的目的是为了2)我调整了鳕鱼e如下:

$('#next').click(function (e) { 
    e.preventDefault(); 
    $('#first').fadeOut('slow', function() { 
    $('#second').fadeIn('slow'); 
    }); 
}); 
$('#back').click(function (e) { 
    e.preventDefault(); 
    $('#second').fadeOut('slow', function() { 
    $('#first').fadeIn('slow'); 
    }); 
}); 
$('#next1').click(function (e) { 
    e.preventDefault(); 
    $('#third').fadeOut('slow', function() { 
    $('#forth').fadeIn('slow'); 
    }); 
}); 
$('#back2').click(function (e) { 
    e.preventDefault(); 
    $('#forth').fadeOut('slow', function() { 
    $('#third').fadeIn('slow'); 
    }); 
}); 
+0

那真棒,现在看起来很简单,谢谢你参加我的下一场战斗 – 2014-10-05 08:44:02