大厦关闭的krembo99's answer he linked here,我想分享我的解决办法,因为我已经上传数百张照片时,我的客户已经要求这样的功能。考虑到这一点,通过在提供的代码中添加一些额外的行,我能够得到一个适合我的参数的解决方案。
我也在使用较小的图片,所以我不需要通过创建同一个文件的较小版本的&。
$('.thumbnails img').click(function(){
// Grab img.thumb class src attribute
// NOTE: ALL img tags must have use this class,
// otherwise you can't click back to the first image.
var thumbSrc = $('.thumb').attr('src');
// Grab img#largeImage src attribute
var largeSrc = $('#largeImage').attr('src');
// Use variables to replace src instead of relying on file names.
$('#largeImage').attr('src',$(this).attr('src').replace(thumbSrc,largeSrc));
$('#description').html($(this).attr('alt'));
});
下面是我的HTML的外观。
<img src="path/to/file1.jpg" id="largeImage" class="thumb">
<div id="description">1st image Description</div>
<div class="thumbnails">
<img src="path/to/file1.jpg" class="thumb" alt="1st image description">
<img src="path/to/file2.jpg" class="thumb"alt="2nd image description">
<img src="path/to/file3.jpg" class="thumb" alt="3rd image description">
<img src="path/to/file4.jpg" class="thumb" alt="4th image description">
<img src="path/to/file5.jpg" class="thumb" alt="5th image description">
</div>
我们做类似的细微变化。 MouseOver Thumnail改变主图像,但不粘,点击拇指使主图像变粘。用户可以将鼠标移到拇指上查看,然后点击他们想要的;如果鼠标移过更多的拇指,主图像将在所有拇指的鼠标移出时恢复。 – Kristen 2009-03-04 22:56:04