Jump to content

Images to appear in random order?

Go to solution Solved by tuanphan,

Recommended Posts

  • Solution

Try adding to Settings > Advanced > Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.gallery-masonry .gallery-masonry-wrapper');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('figure');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • Eunice_SQSP changed the title to Images to appear in random order?
  • 1 month later...
On 5/23/2023 at 5:16 PM, mportch said:

Hi,

The images on DESKTOP version still click to a new window. But they no longer click to a new window on MOBILE version. Do you know how to fix this?

https://smilodon-ocelot-my5f.squarespace.com/gallery

 

You have this code in Code Injection or Page Header, it disabled click event

 <style>
            @media screen and (max-width: 767px) {
                #page .gallery a {
                    pointer-events: none;
                }
            </style>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 9 months later...
On 4/5/2023 at 3:44 AM, tuanphan said:

Try adding to Settings > Advanced > Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.gallery-masonry .gallery-masonry-wrapper');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('figure');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

Thank you very much. This worked like a charm!

Link to comment
  • 4 weeks later...
On 4/5/2023 at 3:44 AM, tuanphan said:

Try adding to Settings > Advanced > Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    const productGrid = document.querySelector('.gallery-masonry .gallery-masonry-wrapper');
    if (productGrid) {
        var productItems = productGrid.querySelectorAll('figure');
        for (var i = productItems.length; i >= 0; i--) {
            productGrid.appendChild(productItems[Math.random() * i | 0]);
        }
    }
});
</script>

 

This works thank you so much!
Would you know of a way to just randomise it once? 
 

Link to comment

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.