【问题标题】:What's the best jQuery "click a thumbnail and change the main image" module?什么是最好的 jQuery“单击缩略图并更改主图像”模块?
【发布时间】:2010-10-11 09:15:40
【问题描述】:

这就是我所拥有的(所有都是动态生成的,如果有影响的话):

  • 图片列表
  • 每张图片的标题
  • 每张图片的缩略图

页面应加载一张全尺寸图片和所有缩略图。当用户单击缩略图时,全尺寸图像会显示带有标题的新图像。如果他们单击另一个缩略图,图片(和标题)会再次更改。

这不是很复杂。几个月前我拼凑了一个解决方案,但我需要再做一次,我正在查看这个糟糕的代码并认为必须有更好的方法(并且知道 jQuery,其他人已经做到了,并且完成了好吧)。

想法?链接?

谢谢!

【问题讨论】:

  • 我们做的类似,略有不同。 MouseOver Thumnail 更改主图像,但不粘,单击缩略图使主图像粘。用户可以将鼠标移到大拇指上查看,然后点击他们想要的;如果鼠标经过更多拇指,则当鼠标移出所有拇指时,主图像将恢复

标签: jquery gallery thumbnails


【解决方案1】:

这里的大多数答案就像用大炮打苍蝇一样!!

$('#thumbs img').click(function(){
    $('#largeImage').attr('src',$(this).attr('src').replace('thumb','large'));
    $('#description').html($(this).attr('alt'));
});

这就是你所需要的 .. 4 行代码。

看这里:gallery-in-4-lines

【讨论】:

  • 和你一起。其他一切似乎都过大了
  • 我完全希望所有的“答案”都这么好 - 多么完美的回应和一个很好的起点……如果你需要,可以添加更多,但这可以归结为。 - 谢谢
【解决方案2】:

【讨论】:

    【解决方案3】:

    这是一个看起来很漂亮并且用 jQuery 编写的:Photo Slider

    还有一个我更喜欢的: Galleria

    【讨论】:

    • 哦,Galleria 很漂亮,正是我想要的!谢谢!
    【解决方案4】:

    基于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>
    

    【讨论】:

      【解决方案5】:

      http://bradblogging.com/jquery/9-jquery-slideshow-applications-you-cannot-miss/

      在 jQuery 中包含 9 种不同照片幻灯片的页面可供使用

      【讨论】:

        【解决方案6】:

        查看我的 Galleria 实现:Garden design Landscaper in Essex Gallery

        【讨论】:

          【解决方案7】:

          试试Galleriffic,它有你需要的一切。

          【讨论】:

            【解决方案8】:

            其中很多脚本已经过时,对我不起作用,另外还需要一组不同的图像作为缩略图。我认真地四处寻找,发现了一些非常简单的东西,就是纯 js,不需要 jquery。

            <html>
            <head>
            <style>
            * {margin:0; padding:0; border:0; outline:0; box-sizing:border-box;}
            .image, .thumb {width:100%; height:100%;}
            #product-image-wrap {position:relative; float:left; width:250px; height:325px; margin:50px 0 50px 50px;}
            #product-image {position:relative; float:left; width:250px; height:250px; border:1px solid #d0d0d0; padding:20px; cursor:pointer; display:inline-block; transition:0.9s;}
            #product-image:hover {opacity:0.7;}
            .product-image-thumbnail {position:relative; float:left; width:55px; height:55px; border:1px solid #d0d0d0; margin-top:20px; padding:10px; cursor:pointer; display:inline-block; transition:0.9s;}
            .product-image-thumbnail:hover {opacity:0.7;}
            .product-image-thumbnail-spacer {position:relative; float:left; width:10px; height:130px;}
            </style>
            
            </head>
            <body>
            
            <div id='product-image-wrap'>
            
            <!-- Main -->
            <div id='product-image'><img src='http://workshop.rs/demo/gallery-in-4-lines/images/image_01_large.jpg' id='0' class='image' alt='image 0'></div>
            
            <!-- Thumbs -->
            <div class='product-image-thumbnail'><img src='http://workshop.rs/demo/gallery-in-4-lines/images/image_01_large.jpg' id='1' class='thumb' onclick='preview(this)' alt='image 0'></div>
            <div class='product-image-thumbnail-spacer'></div>
            <div class='product-image-thumbnail'><img src='http://workshop.rs/demo/gallery-in-4-lines/images/image_02_large.jpg' id='2' class='thumb' onclick='preview(this)' alt='image 2'></div>
            <div class='product-image-thumbnail-spacer'></div>
            <div class='product-image-thumbnail'><img src='http://workshop.rs/demo/gallery-in-4-lines/images/image_03_large.jpg' id='3' class='thumb' onclick='preview(this)' alt='image 3'></div>
            <div class='product-image-thumbnail-spacer'></div>
            <div class='product-image-thumbnail'><img src='http://workshop.rs/demo/gallery-in-4-lines/images/image_04_large.jpg' id='4' class='thumb' onclick='preview(this)' alt='image 4'></div>
            
            </div>
            
            <!-- Javascript -->
            <script>
            var lastImg = 1;
            document.getElementById(lastImg).className = "thumb selected";
            function preview(img) {
            document.getElementById(lastImg).className = "thumb";
            img.className = "thumb selected";
            document.getElementById(0).src = img.src;
            lastImg = img.id;
            }
            </script>
            
            </body>
            </html>
            

            https://jsfiddle.net/uo6js5v7/

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2017-10-09
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-08-07
              • 1970-01-01
              相关资源
              最近更新 更多