Comments on: Infinite Marquee Animation using Modern CSS https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/ Helping Your Journey to Senior Developer Fri, 15 Aug 2025 06:28:45 +0000 hourly 1 https://wordpress.org/?v=6.8.3 By: Alex https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-37146 Fri, 15 Aug 2025 06:28:45 +0000 https://frontendmasters.com/blog/?p=6673#comment-37146 This code works fine only when slides are equal by width
If you want the width of slides to be dynamic, you need to use Javascript
And if you want to control speed of slides by some condition (e.g. mouse hover) you must use JS too
There is one of the solution. It’s quite bigger, but it works and you can easily customise it

    .slider {
      overflow-x: hidden;
    }

.slider-track {
  display: flex;
  align-items: center;
}

.slide {
  margin-right: 64px;
  flex-shrink: 0
}
  const initSlider = () => {
    const DEFAULT_SPEED = 2;

    const slider = document.querySelector(".slider");
    if (!slider) return;

    const wrapper = document.querySelector(".slider-track");

    wrapper.innerHTML += wrapper.innerHTML;

    let speed = DEFAULT_SPEED;
    let position = 0;

    slider.addEventListener("mouseenter", () => {
      speed = DEFAULT_SPEED / 2;
    });

    slider.addEventListener("mouseleave", () => {
      speed = DEFAULT_SPEED;
    });

    function animate() {
      position -= speed;

      if (Math.abs(position) >= wrapper.scrollWidth / 2) {
        position = 0;
      }

      wrapper.style.transform = `translateX(${position}px)`;
      requestAnimationFrame(animate);
    }

    animate();
  }

  initSlider();

[EDITOR’s NOTE]: Use Markdown triple-backtick code blocks to post code here so it gets escaped properly. Or make a Pen: pen.new. I’m not sure the above code posted correctly.

]]>
By: King777 https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-36814 Mon, 11 Aug 2025 09:56:39 +0000 https://frontendmasters.com/blog/?p=6673#comment-36814 This is truly an exciting art! Thanks for the analysis and the illustrative example of using sibling-*() functions – the flexibility and dynamism is impressive!

]]>
By: Chris Coyier https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-36414 Wed, 06 Aug 2025 17:56:11 +0000 https://frontendmasters.com/blog/?p=6673#comment-36414 In reply to Tommy.

Temani specifically says at the top: https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#:~:text=At%20the%20time%20of%20writing%2C%20only%20Chrome%2Dbased%20browsers

Your phone is probably an iPhone, and all browsers (booooooooo) on iPhone are Safari.

]]>
By: Chris Coyier https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-36413 Wed, 06 Aug 2025 17:55:41 +0000 https://frontendmasters.com/blog/?p=6673#comment-36413 In reply to Jakub.

Temani specifically says at the top: https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#:~:text=At%20the%20time%20of%20writing%2C%20only%20Chrome%2Dbased%20browsers

]]>
By: Tommy https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-36406 Wed, 06 Aug 2025 16:30:58 +0000 https://frontendmasters.com/blog/?p=6673#comment-36406 The marquees are not moving in Chrome on my phone, does this mean right now it’s limited to desktop Chrome?

]]>
By: Jakub https://frontendmasters.com/blog/infinite-marquee-animation-using-modern-css/#comment-36404 Wed, 06 Aug 2025 16:15:14 +0000 https://frontendmasters.com/blog/?p=6673#comment-36404 Doesn’t work on mobile – iOS 26, Safari, Brave, Google app

]]>