Jump to content

Image Gallery Random Order

Go to solution Solved by Ziggy,

Recommended Posts

Posted

Hello, 

I am using an image gallery (slideshow: full, full bleed, large height) for my homepage and want the images autoplay in a random order, as well as be a different image every time the homepage is opened. Is there a code that can be used to do this? I have seen other forums for people doing this with other gallery types, but not for slideshow:full.

Thanks for the help, Ethan

Posted

I have tried a code provided by tuanphan on elfsight.com for how to randomize a full gallery, however that method adds a large white space at below the image gallery, and I want the homepage to not scroll and only be the image gallery and header. It also sometimes loads a white screen instead of an image and takes a few seconds to go to an image. 

Thanks

  • Solution
Posted

I've adjusted the code from here:

Try this in Header Code Injection:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
 $( document ).ready(function() {
   $('.gallery-fullscreen-slideshow-list').randomize('figure.gallery-fullscreen-slideshow-item');
 });
 (function($) {
   $.fn.randomize = function(childElem) {
       function shuffle(o) {
           for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x =
o[--i], o[i] = o[j], o[j] = x);
           return o;
       };
       return this.each(function() {
           var $this = $(this);
           var elems = $this.children(childElem);
           shuffle(elems);
           $this.detach(childElem);
           for(var i=0; i < elems.length; i++) {
               $this.append(elems[i]);
} });
   }
})(jQuery);
</script>

If that doesn't work, can you share your website URL so I can double-check the classes on your website.

Please like and upvote if my comments were helpful to you. Cheers!

Zygmunt Spray
Squarespace Website Designer
Contact me: 
https://squarefortytwo.com 
Hire me on Upwork!

📈 SEO Space (Referral link)
Ⓜ️ 
Will Myers' Plugins & Tutorials (Referral link)
 🔌 Ghost Squarespace Plugins (Referral link)
 SquareWebsites Plugins (Referral link)
 🔲SQSP Themes (Referral link) 
Spark Plugin (Referral link) 
 🖼️Pinch-to-Zoom Gallery Lightbox Plugin (Referral link) 

 Did I help? Buy me a coffee?

Posted

It does appear to be working when I test it, but have the slideshow auto-playing does make it harder to tell! Try disabling that and then loading the page in a private browser window multiple times to see it working.

Please like and upvote if my comments were helpful to you. Cheers!

Zygmunt Spray
Squarespace Website Designer
Contact me: 
https://squarefortytwo.com 
Hire me on Upwork!

📈 SEO Space (Referral link)
Ⓜ️ 
Will Myers' Plugins & Tutorials (Referral link)
 🔌 Ghost Squarespace Plugins (Referral link)
 SquareWebsites Plugins (Referral link)
 🔲SQSP Themes (Referral link) 
Spark Plugin (Referral link) 
 🖼️Pinch-to-Zoom Gallery Lightbox Plugin (Referral link) 

 Did I help? Buy me a coffee?

Posted (edited)

It does appear to be working now, but for some reason when opening the home page, it will still show the same first image for a split second then go to a random image. It makes it look like there is a glitch. Is there a way to fix that?

Thanks again for the help

Edited by EthanK1

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.