クリックするとフルサイズに拡大し、もう一度クリックすると元のサイズに戻る写真のギャラリーを作成しています...私の問題は、複数の写真をクリックすると、それらがすべて拡大され、最初のものは元のサイズに戻ります。拡大するためにクリックしたときに他のすべての写真を強制的に小さいサイズに戻す簡単な方法があるかどうか、または拡大された写真から離れた場所をクリックする必要があるようにする方法があるかどうか疑問に思っています小さいサイズに戻します。
これが私のコードです。下部にあるフィドルリンクです(2番目の写真をクリックしてから最初の写真をクリックして、私が話していることを確認してください)
<div id="Gpic1">
<img class='galleryPics' id='pic1' src='http://i.imgur.com/urxD24P.jpg?1'>
</div>
<div id="Gpic2">
<img class='galleryPics' id='pic2' src='http://i.imgur.com/JbJXjsf.jpg?1'>
</div>
#Gpic1 {
float: left;
width: 187px;
height: 280px;
margin-left: 5%;
display: inline-block;
background: black;
padding: 0;
}
#pic1 {
width: 187px;
height: 280px;
}
#Gpic2 {
float: left;
width: 187px;
height: 280px;
margin-left: 5%;
display: inline-block;
background: black;
padding: 0;
}
#pic2 {
width: 187px;
height: 280px;
}
.enlarged {
border: 10px solid #e5dbcc;
position: absolute;
-webkit-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
}
$('#Gpic1').hover(function () {
if (!$(this).find('img').hasClass('enlarged')) {
$(this).find('img').fadeTo(500, 0.5);
}
}, function () {
$(this).find('img').fadeTo(500, 1);
});
$('#pic1').click(function () {
$(this).fadeTo(0, 1);
if ($(this).hasClass('enlarged')) {
$(this).removeClass('enlarged');
$(this).stop().animate({
width: 187,
height: 280
}, 0,
function () {
$(this).parent().removeClass('ontop');
$('#Gpic1').css('background', 'black');
});
} else {
$(this).addClass('enlarged')
$(this).parent().addClass('ontop');
$(this).stop().animate({
width: 533,
height: 800,
left: +100,
bottom: +50
}, 200);
$('#Gpic1').css('background', 'none');
}
});
$('#Gpic2').hover(function () {
if (!$(this).find('img').hasClass('enlarged')) {
$(this).find('img').fadeTo(500, 0.5);
}
}, function () {
$(this).find('img').fadeTo(500, 1);
});
$('#pic2').click(function () {
$(this).fadeTo(0, 1);
if ($(this).hasClass('enlarged')) {
$(this).removeClass('enlarged');
$(this).stop().animate({
width: 187,
height: 280
}, 0,
function () {
$(this).parent().removeClass('ontop');
$('#Gpic2').css('background', 'black');
});
} else {
$(this).addClass('enlarged')
$(this).parent().addClass('ontop');
$(this).stop().animate({
width: 533,
height: 800,
left: +100,
bottom: +50
}, 200);
$('#Gpic2').css('background', 'none');
}
});
編集 ---- フィドル: http://jsfiddle.net/Td6tT/4/