Jump to content

TWO Carousels Auto Scroll

Go to solution Solved by Beyondspace,

Recommended Posts

Hello! 

I'm trying to design a single page with TWO automatically scrolling carousels. I injected the following code into my footer, but it only made ONE of the carousels auto scroll.  The second carousel only scrolls when clicked. I placed the carousels in different sections (instead of the same section), but that didn't help.

Any idea how to correct this issue? Cheers 🙂

 

<!-- Summary Block Autoplay -->
<script>
window.onload = function() {
  var nextArrow = document.querySelector(".summary-carousel-pager-next");
  
  function clickNext() {
    nextArrow.click();
  }
 
  setInterval(clickNext, 4000);
};
</script>

Link to comment

Hello!

It is simple to solve.
A new line of code will be needed.
Include the link of the page so I can create the rest of the code.

Link to comment

Password?

Link to comment
  • Solution
On 3/13/2024 at 1:30 AM, cookiemonster said:

Hello! 

I'm trying to design a single page with TWO automatically scrolling carousels. I injected the following code into my footer, but it only made ONE of the carousels auto scroll.  The second carousel only scrolls when clicked. I placed the carousels in different sections (instead of the same section), but that didn't help.

Any idea how to correct this issue? Cheers 🙂

 

<!-- Summary Block Autoplay -->
<script>
window.onload = function() {
  var nextArrow = document.querySelector(".summary-carousel-pager-next");
  
  function clickNext() {
    nextArrow.click();
  }
 
  setInterval(clickNext, 4000);
};
</script>

Try

<script>
// Check if the window is loaded
window.onload = function() {
    if (window.self !== window.top) {
    	return;
    }
  	// Function to simulate clicking the next arrow
    function clickNext(arrow) {
        arrow.click();
    }

    // Query all elements with the class for carousel next arrows
    var nextArrows = document.querySelectorAll(".summary-carousel-pager-next");

    // Set auto-scrolling for each carousel
    nextArrows.forEach(function(arrow) {
        // Define a function to handle auto-scrolling for a specific carousel
        function autoScroll() {
            clickNext(arrow);
            setTimeout(autoScroll, 4000); // Set the next auto-scroll after 4 seconds
        }

        // Start the auto-scrolling for the current carousel
        autoScroll();
    });
}
</script>

If you want all your summaries on your site to auto run, place this code in your site Footer injection. Otherwise place it into each Page code injection 

BeyondSpace - Squarespace Website Developer

🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox)
🗓️ Delivery Date Picker (Squarespace Date picker form field)
💫 Gallery block 7.1 workaround
🥳 Sparkplugin Customisations Browsers (Browse +100 Spark plugin customisations)
🥳 Elfsight Template Browsers (Browse +1000 Elfsight widget Templates)

If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you!

 

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.