我希望能够检测主要图片中的图像大小,如果其高度超过一定值,则将图像设置为特定高度。目前存在问题是它似乎只能检测到第一个图像,并且在通过点击缩略图选择另一个图像时目前不具有响应性。
所有放置在主要图片区域的图像都应该居中显示。
JavaScript代码无法运行,但我认为我正在朝着正确的方向前进。
所有放置在主要图片区域的图像都应该居中显示。
JavaScript代码无法运行,但我认为我正在朝着正确的方向前进。
$('.thumb-box').click(function() {
$(this).parent('.main-image').attr('src', '.thumb-box > img').fadeIn();
});
//Resize image
$('.main-image').each(function() {
if ($(this).height() > 550) { $(this).addClass('higher-than-max'); }
else if ($(this).height() <= 550) {$(this).addClass('not-higher-than-max');}
});
.parent{
border:1px solid purple;
height:100%;
width:80%;
float:Right;
}
.child{
border:1px solid red;
height:100%;
background:gray;
text-align:center;
}
.child-img{
display:inline-block;
max-width:100%;
margin:0 auto;
}
.image-wrapper{
width:100%;
background:orange;
}
.thumbnails img{
width:auto;
height:100%;
width:100%;
}
.thumbnails{
width:100px;
height:100px;
}
.thumb-box{
height:40%;
width:40%;
display:inline-block;
background:red;
}
.higher-than-max{
max-height:500px;
width:auto;
}
.not-higher-than-max{
max-height:100%;
width:auto;
}
<div class="parent">
<div class="child">
<div class="image-wrapper">
<img src="http://vignette2.wikia.nocookie.net/pokemon/images/b/b1/025Pikachu_XY_anime_3.png/revision/latest?cb=20140902050035" alt="374x333" class="main-image">
<div class="thumbnails">
<div class="thumb-box">
<img src="http://vignette2.wikia.nocookie.net/pokemon/images/b/b1/025Pikachu_XY_anime_3.png/revision/latest?cb=20140902050035" alt="374x333" class="child-img"> </div>
<div class="thumb-box">
<img src="https://i.kinja-img.com/gawker-media/image/upload/unnbgkdbmsszmazgxkmr.jpg" alt="800x450" class="child-img"></div>
<div class="thumb-box">
<img src="http://vignette3.wikia.nocookie.net/scratchpad/images/0/02/Pikachu.gif/revision/latest?cb=20150217015901" alt="" class="child-img">
</div>
<div class="thumb-box">
<img src="http://cdn.bulbagarden.net/upload/thumb/0/0d/025Pikachu.png/250px-025Pikachu.png" alt="" class="child-img">
</div>
</div>
</div>
</div>