Adding Thumbnails to PhotoSwipe [MY SOLUTION]

See original GitHub issue

Just to share…

How to add thumbnails to Photoswipe:

Add some css:

div.photoSwipe_innerthumbs{position: fixed; bottom: 0; width: 100%; text-align: center;z-index: 1000000;}
div.photoSwipe_innerthumbs img{max-width: 100px; cursor: pointer;}
.svifaded{opacity: 0.5;}

Custom JS:

var pswpElement = document.querySelectorAll('.pswp')[0];

$('body').on('click', 'div#mainimage img', function (e) {
    $('body').append('<div class="photoSwipe_innerthumbs"></div>');

    var svi_items = [];

    $('div#thumbnails li').each(function (i, v) {    // build items array
        svi_items.push({
            src: $(v).data('imgfull'),
            w: $(v).data('imgw'),
            h: $(v).data('imgv'),
            msrc: $(v).data('imgthumb'),
            title: $(v).find('img').attr('title')
        });
    });

    // define options (if needed)
    var options = {
        index: 0 // start at first slide
    };

    // Initializes and opens PhotoSwipe
    gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, svi_items, options);

    gallery.init();

// Gallery starts closing
    gallery.listen('close', function () {
        $('.photoSwipe_innerthumbs').remove();
    });

//Clone and append the thumbnail images
    $('div#thumbnails img').clone().appendTo("div.photoSwipe_innerthumbs");

//Get current active index and add class to thumb just to fade a bit
    $("div.photoSwipe_innerthumbs img").eq(gallery.getCurrentIndex()).addClass('svifaded');

//Handle the swaping of images
    $('body').on('click', 'div.photoSwipe_innerthumbs img', function (e) {
        $('div.photoSwipe_innerthumbs img').removeClass("svifaded");
        $(this).addClass('svifaded');
        gallery.goTo($("div.photoSwipe_innerthumbs img").index($(this)));
    });
});

Sample image: photoswipethumb

I searched for other people doing this, but didn’t find… 👍

PS: The thumbnails are not responsive, if you want to share a solution for this will be welcomed… 😃

PS: Missing some type of animation on click, would be great if possible.

Thanks, David

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:16

github_iconTop GitHub Comments

5reactions
Grawlcommented, Jul 14, 2020
4reactions
drosendocommented, Oct 25, 2017

nothing more to add here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Options - PhotoSwipe
If set to true you'll be able to swipe from the last to the first image. Option is always false when there are...
Read more >
Photoswipe Thumbnail Image Size Issues - Trying to Resize ...
I'm basically not using thumbnails, but instead passing in original photos. But I tried resizing the photos to about a thumbnail size, and...
Read more >
Demo Page: PhotoSwipe Gallery - 三只猫的温暖
Yet an improved solution would be to set the thumbnail to a very small size, say max-width: 10px; , so the slide would...
Read more >
thumbnail captions [desperately needed] [#2984783] - Drupal
thumbnail captions [desperately needed]. Closed (won't fix). Project: PhotoSwipe - Responsive JavaScript Modal Image Gallery. Version:.
Read more >
ImageGalleryPlugin < System < SedWiki
Images and thumbnails are resized according to the given settings and are ... class, add an additional css class attribute to the image...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found