Jump to content

How can I create a carousel that enlarges the centre image while scrolling?

Recommended Posts

  • Replies 2
  • Views 103
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted

your site is private , I can' access. I am giving a solution . 

Add this code into custom css:

#scroll-image {
  width: 100px; /* Starting width */
  height: auto; /* Maintain aspect ratio */
  transition: width 0.3s ease, height 0.3s ease; /* Smooth resizing */
}

Here #scroll-image will be replaced by your targeted image id. 

Then add this code into code injection>footer:

document.addEventListener("DOMContentLoaded", function () {
  const scrollImage = document.getElementById("scroll-image");
  let lastScrollY = window.scrollY;

  window.addEventListener("scroll", function () {
    const currentScrollY = window.scrollY;

    if (scrollImage) {
      if (currentScrollY > lastScrollY) {
        // User is scrolling down, increase image size
        scrollImage.style.width = "150px"; // Adjust size as needed
      } else {
        // User is scrolling up, decrease image size
        scrollImage.style.width = "100px"; // Adjust size as needed
      }
    }

    // Update the last scroll position
    lastScrollY = currentScrollY;
  });
});

Here  scroll-image will be replaced by your image id.  

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.