我想创建一个功能,我可以从几张照片中进行选择,如果我点击一张,它应该会在同样显示的大框架中发生变化(照片)。
我想我可能弄乱了选择器。
HTML
<div id="photo">
<img src="http://hd.highresolution-wallpapers.net/wallpapers/space_dimesional_sun-600x800.jpg" alt="Space" />
</div>
<div id="gallery">
<ul>
<li class="selected"><a href="http://hd.highresolution-wallpapers.net/wallpapers/space_dimesional_sun-600x800.jpg"><img src="http://hd.highresolution-wallpapers.net/wallpapers/space_dimesional_sun-600x800.jpg" alt="Space" /></a>
</li>
<li><a href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSh_AgoWSwWBYuvqlbD7kzIrtcPRCV3jGzn5H4fosJRba8JzE1-Ow"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSh_AgoWSwWBYuvqlbD7kzIrtcPRCV3jGzn5H4fosJRba8JzE1-Ow" alt="Grass" /></a>
</li>
<li><a href="http://sitch.org/sailing/images/2006-11-17__sun__600_800.jpg"><img src="http://sitch.org/sailing/images/2006-11-17__sun__600_800.jpg" alt="Water" /></a>
</li>
</ul>
</div>
Javascript
$('.selected').fadeIn();
$("#gallery ul li").on("click", function () {
var selector = '#gallery ul li[src="' + $(this).attr('href') + '"]';
$(".selected").hide();
$("#gallery ul li").fadeIn();
return false;
});
$('#gallery ul li img').on('click', function () {
$(".selected").hide();
var next = $(this).next();
if (next.length > 0) {
next.fadeIn();
} else {
$('.selected').fadeIn();
}
return false;
});