Hi, I’m looking for a photo gallery that re-shuffles on every page load. Is there any galleries out there that do that? I don’t want images to stay in the same spot in the gallery.
Thanks!!
Hi, I’m looking for a photo gallery that re-shuffles on every page load. Is there any galleries out there that do that? I don’t want images to stay in the same spot in the gallery.
Thanks!!
This is not built into the Gallery component, but you could achieve the effect by applying some sort of random function to the Gallery. You can add .skip(random number) to your query, or just shuffle the results of the query using some sort of random function, or whatever else you can think of.
Good luck,
Yisrael
How would you go about adding this code to the gallery? Any help, would be very much appreciated!
Im not a coder but I would like to be able to randomise the layout of images on my homepage each time it is viewed. Is there a simple way you could walk me though adding this code to my site?
@bencheckley Take a look at the Random Image example .
Hello, I was wrestling with the same issue. Some points I discovered:
The code I used looks like this:
let sponsors = $w(‘#gallery5’).items;
sponsors.sort(()=>Math.random()-0.5);
$w(‘#gallery5’).items = sponsors;
That works so far. First, retrieve the array of items of the gallery (here gallery5) into a separate variable (here called sponsors because that makes sense in my context), sort that and then set the gallery items to that variable. Searching around revealed, there might be better methods to randomize an array of items, but this one seems to be sufficient for me.