Landing Page Images shuffle

Step 1: Wrap all posts inside a parent container

<div id="post-container">
    <!-- all your post <a> ... </a> blocks here -->
</div>

Step 2: Add this JavaScript at the bottom of the page

<script>
    function shufflePosts() {
        const container = document.getElementById("post-container");
        const posts = Array.from(container.children);

        // Shuffle using Fisher–Yates algorithm
        for (let i = posts.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            container.appendChild(posts[j]); // moves node → randomizes order
            posts[j] = posts[i];
        }
    }

    shufflePosts();
</script>



No comments:

Post a Comment

Pages